Skip to content

Commit

Permalink
fix(color-generator): consistently format value as hex color (#3282)
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-perkins authored Dec 4, 2023
1 parent 803a655 commit bc85859
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/components/page/theming/ColorGenerator/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from 'react';
import React, { Fragment, useEffect, useRef, useState } from 'react';

import styles from './styles.module.scss';

Expand Down Expand Up @@ -49,6 +49,7 @@ const ColorGenerator = (props) => {

return (
<li
key={name}
className={clsx(styles.item, { [styles.isOpen]: isOpen })}
onClick={() => setActiveColor(activeColor === name ? null : name)}
>
Expand Down Expand Up @@ -97,15 +98,15 @@ const ColorGenerator = (props) => {
:root {'{'}
{'\n'}
{Object.entries(colors).map(([name, color], i) => (
<>
<Fragment key={i}>
{'\t'}--ion-color-{name}: {color.value};{'\n'}
{'\t'}--ion-color-{name}-rgb: {color.valueRgb};{'\n'}
{'\t'}--ion-color-{name}-contrast: {color.contrast};{'\n'}
{'\t'}--ion-color-{name}-contrast-rgb: {color.contrastRgb};{'\n'}
{'\t'}--ion-color-{name}-shade: {color.shade};{'\n'}
{'\t'}--ion-color-{name}-tint: {color.tint};{'\n'}
{'\n'}
</>
</Fragment>
))}
{'}'}
{'\n'}
Expand Down
3 changes: 2 additions & 1 deletion src/components/page/theming/_utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ export const generateColor = (value: string): ColorVariable => {
const contrast = color.contrast();
const tint = color.tint();
const shade = color.shade();
const formattedValue = value.startsWith('#') ? value : `#${value}`;

return {
value,
value: formattedValue,
valueRgb: rgbToString(color.rgb),
contrast: contrast.hex,
contrastRgb: rgbToString(contrast.rgb),
Expand Down

1 comment on commit bc85859

@vercel
Copy link

@vercel vercel bot commented on bc85859 Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ionic-docs – ./

ionic-docs-gqykycf8t.vercel.app
ionic-docs-git-main-ionic1.vercel.app
ionic-docs-ionic1.vercel.app

Please sign in to comment.