Skip to content

Commit bc85859

Browse files
authored
fix(color-generator): consistently format value as hex color (#3282)
1 parent 803a655 commit bc85859

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/components/page/theming/ColorGenerator/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef, useState } from 'react';
1+
import React, { Fragment, useEffect, useRef, useState } from 'react';
22

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

@@ -49,6 +49,7 @@ const ColorGenerator = (props) => {
4949

5050
return (
5151
<li
52+
key={name}
5253
className={clsx(styles.item, { [styles.isOpen]: isOpen })}
5354
onClick={() => setActiveColor(activeColor === name ? null : name)}
5455
>
@@ -97,15 +98,15 @@ const ColorGenerator = (props) => {
9798
:root {'{'}
9899
{'\n'}
99100
{Object.entries(colors).map(([name, color], i) => (
100-
<>
101+
<Fragment key={i}>
101102
{'\t'}--ion-color-{name}: {color.value};{'\n'}
102103
{'\t'}--ion-color-{name}-rgb: {color.valueRgb};{'\n'}
103104
{'\t'}--ion-color-{name}-contrast: {color.contrast};{'\n'}
104105
{'\t'}--ion-color-{name}-contrast-rgb: {color.contrastRgb};{'\n'}
105106
{'\t'}--ion-color-{name}-shade: {color.shade};{'\n'}
106107
{'\t'}--ion-color-{name}-tint: {color.tint};{'\n'}
107108
{'\n'}
108-
</>
109+
</Fragment>
109110
))}
110111
{'}'}
111112
{'\n'}

src/components/page/theming/_utils/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ export const generateColor = (value: string): ColorVariable => {
1313
const contrast = color.contrast();
1414
const tint = color.tint();
1515
const shade = color.shade();
16+
const formattedValue = value.startsWith('#') ? value : `#${value}`;
1617

1718
return {
18-
value,
19+
value: formattedValue,
1920
valueRgb: rgbToString(color.rgb),
2021
contrast: contrast.hex,
2122
contrastRgb: rgbToString(contrast.rgb),

0 commit comments

Comments
 (0)