Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Does not affect public API surface.

"comment": "chore: Refactor global shared color tokens",
"packageName": "@fluentui/react-theme",
"email": "miroslav.stastny@microsoft.com",
"dependentChangeType": "none"
}
60 changes: 60 additions & 0 deletions packages/react-components/react-theme/src/alias/colorPalette.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* Names of colors used in shared color palette alias tokens for status. */
export const statusSharedColorNames = [
'red',
'green',
'darkOrange',
'yellow',
'berry',
'lightGreen',
'marigold',
] as const;

/* Names of colors used in shared color palette alias tokens for persona. */
export const personaSharedColorNames = [
'darkRed',
'cranberry',
'pumpkin',
'peach',
'gold',
'brass',
'brown',
'forest',
'seafoam',
'darkGreen',
'lightTeal',
'teal',
'steel',
'blue',
'royalBlue',
'cornflower',
'navy',
'lavender',
'purple',
'grape',
'lilac',
'pink',
'magenta',
'plum',
'beige',
'mink',
'platinum',
'anchor',
] as const;

/* Names of colors not used in alias tokens but produced by token pipeline as global color tokens. */
export const unusedSharedColorNames = [
'burgundy',
'bronze',
'orange',
'darkBrown',
'lime',
'darkTeal',
'cyan',
'lightBlue',
'darkBlue',
'darkPurple',
'orchid',
'hotPink',
'silver',
'charcoal',
] as const;
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
import { statusSharedColors, personaSharedColors, StatusSharedColors, PersonaSharedColors } from '../global/colors';
import { ColorPaletteTokens, GlobalSharedColors, PersonaColorPaletteTokens, StatusColorPaletteTokens } from '../types';
import { sharedColors } from '../global/colors';
import { statusSharedColorNames, personaSharedColorNames } from './colorPalette';
import { ColorPaletteTokens, PersonaColorPaletteTokens, StatusColorPaletteTokens } from '../types';

const statusColorPaletteTokens = (Object.keys(statusSharedColors) as Array<
keyof Pick<GlobalSharedColors, StatusSharedColors>
>).reduce((acc, sharedColor) => {
const statusColorPaletteTokens = statusSharedColorNames.reduce((acc, sharedColor) => {
const color = sharedColor.slice(0, 1).toUpperCase() + sharedColor.slice(1);
const sharedColorTokens = {
[`colorPalette${color}Background1`]: statusSharedColors[sharedColor].shade40,
[`colorPalette${color}Background2`]: statusSharedColors[sharedColor].shade30,
[`colorPalette${color}Background3`]: statusSharedColors[sharedColor].primary,
[`colorPalette${color}Foreground1`]: statusSharedColors[sharedColor].tint30,
[`colorPalette${color}Foreground2`]: statusSharedColors[sharedColor].tint40,
[`colorPalette${color}Foreground3`]: statusSharedColors[sharedColor].tint20,
[`colorPalette${color}BorderActive`]: statusSharedColors[sharedColor].tint30,
[`colorPalette${color}Border1`]: statusSharedColors[sharedColor].primary,
[`colorPalette${color}Border2`]: statusSharedColors[sharedColor].tint20,
[`colorPalette${color}Background1`]: sharedColors[sharedColor].shade40,
[`colorPalette${color}Background2`]: sharedColors[sharedColor].shade30,
[`colorPalette${color}Background3`]: sharedColors[sharedColor].primary,
[`colorPalette${color}Foreground1`]: sharedColors[sharedColor].tint30,
[`colorPalette${color}Foreground2`]: sharedColors[sharedColor].tint40,
[`colorPalette${color}Foreground3`]: sharedColors[sharedColor].tint20,
[`colorPalette${color}BorderActive`]: sharedColors[sharedColor].tint30,
[`colorPalette${color}Border1`]: sharedColors[sharedColor].primary,
[`colorPalette${color}Border2`]: sharedColors[sharedColor].tint20,
};

return { ...acc, ...sharedColorTokens };
}, {} as StatusColorPaletteTokens);

const personaColorPaletteTokens = (Object.keys(personaSharedColors) as Array<
keyof Pick<GlobalSharedColors, PersonaSharedColors>
>).reduce((acc, sharedColor) => {
const personaColorPaletteTokens = personaSharedColorNames.reduce((acc, sharedColor) => {
const color = sharedColor.slice(0, 1).toUpperCase() + sharedColor.slice(1);
const sharedColorTokens = {
[`colorPalette${color}Background2`]: personaSharedColors[sharedColor].shade30,
[`colorPalette${color}Foreground2`]: personaSharedColors[sharedColor].tint40,
[`colorPalette${color}BorderActive`]: personaSharedColors[sharedColor].tint30,
[`colorPalette${color}Background2`]: sharedColors[sharedColor].shade30,
[`colorPalette${color}Foreground2`]: sharedColors[sharedColor].tint40,
[`colorPalette${color}BorderActive`]: sharedColors[sharedColor].tint30,
};

return { ...acc, ...sharedColorTokens };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import {
statusSharedColors,
personaSharedColors,
hcHighlight,
white,
black,
StatusSharedColors,
PersonaSharedColors,
} from '../global/colors';
import { ColorPaletteTokens, GlobalSharedColors, PersonaColorPaletteTokens, StatusColorPaletteTokens } from '../types';
import { hcHighlight, white, black } from '../global/colors';
import { statusSharedColorNames, personaSharedColorNames } from './colorPalette';
import { ColorPaletteTokens, PersonaColorPaletteTokens, StatusColorPaletteTokens } from '../types';

const statusColorPaletteTokens = (Object.keys(statusSharedColors) as Array<
keyof Pick<GlobalSharedColors, StatusSharedColors>
>).reduce((acc, sharedColor) => {
const statusColorPaletteTokens = statusSharedColorNames.reduce((acc, sharedColor) => {
const color = sharedColor.slice(0, 1).toUpperCase() + sharedColor.slice(1);
const sharedColorTokens = {
[`colorPalette${color}Background1`]: white,
Expand All @@ -28,9 +19,7 @@ const statusColorPaletteTokens = (Object.keys(statusSharedColors) as Array<
return { ...acc, ...sharedColorTokens };
}, {} as StatusColorPaletteTokens);

const personaColorPaletteTokens = (Object.keys(personaSharedColors) as Array<
keyof Pick<GlobalSharedColors, PersonaSharedColors>
>).reduce((acc, sharedColor) => {
const personaColorPaletteTokens = personaSharedColorNames.reduce((acc, sharedColor) => {
const color = sharedColor.slice(0, 1).toUpperCase() + sharedColor.slice(1);
const sharedColorTokens = {
[`colorPalette${color}Background2`]: black,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
import { statusSharedColors, personaSharedColors, StatusSharedColors, PersonaSharedColors } from '../global/colors';
import { ColorPaletteTokens, GlobalSharedColors, PersonaColorPaletteTokens, StatusColorPaletteTokens } from '../types';
import { sharedColors } from '../global/colors';
import { statusSharedColorNames, personaSharedColorNames } from './colorPalette';
import { ColorPaletteTokens, PersonaColorPaletteTokens, StatusColorPaletteTokens } from '../types';

const statusColorPaletteTokens = (Object.keys(statusSharedColors) as Array<
keyof Pick<GlobalSharedColors, StatusSharedColors>
>).reduce((acc, sharedColor) => {
const statusColorPaletteTokens = statusSharedColorNames.reduce((acc, sharedColor) => {
const color = sharedColor.slice(0, 1).toUpperCase() + sharedColor.slice(1);
const sharedColorTokens = {
[`colorPalette${color}Background1`]: statusSharedColors[sharedColor].tint60,
[`colorPalette${color}Background2`]: statusSharedColors[sharedColor].tint40,
[`colorPalette${color}Background3`]: statusSharedColors[sharedColor].primary,
[`colorPalette${color}Foreground1`]: statusSharedColors[sharedColor].shade10,
[`colorPalette${color}Foreground2`]: statusSharedColors[sharedColor].shade30,
[`colorPalette${color}Foreground3`]: statusSharedColors[sharedColor].primary,
[`colorPalette${color}BorderActive`]: statusSharedColors[sharedColor].primary,
[`colorPalette${color}Border1`]: statusSharedColors[sharedColor].tint40,
[`colorPalette${color}Border2`]: statusSharedColors[sharedColor].primary,
[`colorPalette${color}Background1`]: sharedColors[sharedColor].tint60,
[`colorPalette${color}Background2`]: sharedColors[sharedColor].tint40,
[`colorPalette${color}Background3`]: sharedColors[sharedColor].primary,
[`colorPalette${color}Foreground1`]: sharedColors[sharedColor].shade10,
[`colorPalette${color}Foreground2`]: sharedColors[sharedColor].shade30,
[`colorPalette${color}Foreground3`]: sharedColors[sharedColor].primary,
[`colorPalette${color}BorderActive`]: sharedColors[sharedColor].primary,
[`colorPalette${color}Border1`]: sharedColors[sharedColor].tint40,
[`colorPalette${color}Border2`]: sharedColors[sharedColor].primary,
};

return { ...acc, ...sharedColorTokens };
}, {} as StatusColorPaletteTokens);

const personaColorPaletteTokens = (Object.keys(personaSharedColors) as Array<
keyof Pick<GlobalSharedColors, PersonaSharedColors>
>).reduce((acc, sharedColor) => {
const personaColorPaletteTokens = personaSharedColorNames.reduce((acc, sharedColor) => {
const color = sharedColor.slice(0, 1).toUpperCase() + sharedColor.slice(1);
const sharedColorTokens = {
[`colorPalette${color}Background2`]: personaSharedColors[sharedColor].tint40,
[`colorPalette${color}Foreground2`]: personaSharedColors[sharedColor].shade30,
[`colorPalette${color}BorderActive`]: personaSharedColors[sharedColor].primary,
[`colorPalette${color}Background2`]: sharedColors[sharedColor].tint40,
[`colorPalette${color}Foreground2`]: sharedColors[sharedColor].shade30,
[`colorPalette${color}BorderActive`]: sharedColors[sharedColor].primary,
};

return { ...acc, ...sharedColorTokens };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
import { statusSharedColors, personaSharedColors, StatusSharedColors, PersonaSharedColors } from '../global/colors';
import { ColorPaletteTokens, GlobalSharedColors, PersonaColorPaletteTokens, StatusColorPaletteTokens } from '../types';
import { sharedColors } from '../global/colors';
import { statusSharedColorNames, personaSharedColorNames } from './colorPalette';
import { ColorPaletteTokens, PersonaColorPaletteTokens, StatusColorPaletteTokens } from '../types';

const statusColorPaletteTokens = (Object.keys(statusSharedColors) as Array<
keyof Pick<GlobalSharedColors, StatusSharedColors>
>).reduce((acc, sharedColor) => {
const statusColorPaletteTokens = statusSharedColorNames.reduce((acc, sharedColor) => {
const color = sharedColor.slice(0, 1).toUpperCase() + sharedColor.slice(1);
const sharedColorTokens = {
[`colorPalette${color}Background1`]: statusSharedColors[sharedColor].shade40,
[`colorPalette${color}Background2`]: statusSharedColors[sharedColor].shade30,
[`colorPalette${color}Background3`]: statusSharedColors[sharedColor].primary,
[`colorPalette${color}Foreground1`]: statusSharedColors[sharedColor].tint30,
[`colorPalette${color}Foreground2`]: statusSharedColors[sharedColor].tint40,
[`colorPalette${color}Foreground3`]: statusSharedColors[sharedColor].tint20,
[`colorPalette${color}BorderActive`]: statusSharedColors[sharedColor].tint30,
[`colorPalette${color}Border1`]: statusSharedColors[sharedColor].primary,
[`colorPalette${color}Border2`]: statusSharedColors[sharedColor].tint20,
[`colorPalette${color}Background1`]: sharedColors[sharedColor].shade40,
[`colorPalette${color}Background2`]: sharedColors[sharedColor].shade30,
[`colorPalette${color}Background3`]: sharedColors[sharedColor].primary,
[`colorPalette${color}Foreground1`]: sharedColors[sharedColor].tint30,
[`colorPalette${color}Foreground2`]: sharedColors[sharedColor].tint40,
[`colorPalette${color}Foreground3`]: sharedColors[sharedColor].tint20,
[`colorPalette${color}BorderActive`]: sharedColors[sharedColor].tint30,
[`colorPalette${color}Border1`]: sharedColors[sharedColor].primary,
[`colorPalette${color}Border2`]: sharedColors[sharedColor].tint20,
};

return { ...acc, ...sharedColorTokens };
}, {} as StatusColorPaletteTokens);

const personaColorPaletteTokens = (Object.keys(personaSharedColors) as Array<
keyof Pick<GlobalSharedColors, PersonaSharedColors>
>).reduce((acc, sharedColor) => {
const personaColorPaletteTokens = personaSharedColorNames.reduce((acc, sharedColor) => {
const color = sharedColor.slice(0, 1).toUpperCase() + sharedColor.slice(1);
const sharedColorTokens = {
[`colorPalette${color}Background2`]: personaSharedColors[sharedColor].shade30,
[`colorPalette${color}Foreground2`]: personaSharedColors[sharedColor].tint40,
[`colorPalette${color}BorderActive`]: personaSharedColors[sharedColor].tint30,
[`colorPalette${color}Background2`]: sharedColors[sharedColor].shade30,
[`colorPalette${color}Foreground2`]: sharedColors[sharedColor].tint40,
[`colorPalette${color}BorderActive`]: sharedColors[sharedColor].tint30,
};

return { ...acc, ...sharedColorTokens };
Expand Down
82 changes: 21 additions & 61 deletions packages/react-components/react-theme/src/global/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,94 +848,54 @@ const charcoal: ColorVariants = {
tint60: '#f7f7f7',
};

export type StatusSharedColors = 'red' | 'green' | 'darkOrange' | 'yellow' | 'berry' | 'lightGreen' | 'marigold';

export const statusSharedColors: Pick<GlobalSharedColors, StatusSharedColors> = {
red,
green,
darkOrange,
yellow,
berry,
lightGreen,
marigold,
};

export type PersonaSharedColors =
| 'darkRed'
| 'cranberry'
| 'pumpkin'
| 'peach'
| 'gold'
| 'brass'
| 'brown'
| 'forest'
| 'seafoam'
| 'darkGreen'
| 'lightTeal'
| 'teal'
| 'steel'
| 'blue'
| 'royalBlue'
| 'cornflower'
| 'navy'
| 'lavender'
| 'purple'
| 'grape'
| 'lilac'
| 'pink'
| 'magenta'
| 'plum'
| 'beige'
| 'mink'
| 'platinum'
| 'anchor';

export const personaSharedColors: Pick<GlobalSharedColors, PersonaSharedColors> = {
export const sharedColors: GlobalSharedColors = {
darkRed,
burgundy,
cranberry,
red,
darkOrange,
bronze,
pumpkin,
orange,
peach,
marigold,
yellow,
gold,
brass,
brown,
darkBrown,
lime,
forest,
seafoam,
lightGreen,
green,
darkGreen,
lightTeal,
teal,
darkTeal,
cyan,
steel,
lightBlue,
blue,
royalBlue,
darkBlue,
cornflower,
navy,
lavender,
purple,
darkPurple,
orchid,
grape,
berry,
lilac,
pink,
hotPink,
magenta,
plum,
beige,
mink,
silver,
platinum,
anchor,
};

// These shared colors are currently not used in themes
// Not exported from the package, we can consider removing them
export const unusedSharedColors = {
burgundy,
bronze,
orange,
darkBrown,
lime,
darkTeal,
cyan,
lightBlue,
darkBlue,
darkPurple,
orchid,
hotPink,
silver,
charcoal,
};
Loading