Skip to content

Commit

Permalink
Merge branch 'main' into dark-theme-buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
sophschneider committed Mar 25, 2024
2 parents 3cd4754 + 13c8ee7 commit b6fe014
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import {
ThemeProvider,
InlineStack,
} from '@shopify/polaris';
import {SidekickIcon, NotificationIcon} from '@shopify/polaris-icons';
import {HeartIcon, NotificationIcon} from '@shopify/polaris-icons';

export default {
component: ThemeProvider,
} as ComponentMeta<typeof ThemeProvider>;

export function Default() {
const [isSidekickMenuOpen, setIsSidekickMenuOpen] = useState(true);
const [isHeartMenuOpen, setIsHeartMenuOpen] = useState(true);

const toggleIsSidekickMenuOpen = useCallback(
() => setIsSidekickMenuOpen((isSidekickMenuOpen) => !isSidekickMenuOpen),
const toggleIsHeartMenuOpen = useCallback(
() => setIsHeartMenuOpen((isHeartMenuOpen) => !isHeartMenuOpen),
[],
);

Expand All @@ -32,22 +32,22 @@ export function Default() {
[],
);

const sidekickMenu = (
const heartMenu = (
<ThemeProvider theme="light">
<TopBar.Menu
activatorContent={
<ThemeProvider theme="dark-experimental">
<span>
<Icon source={SidekickIcon} />
<Icon source={HeartIcon} />
<Text as="span" visuallyHidden>
Light theme popover button
</Text>
</span>
</ThemeProvider>
}
open={isSidekickMenuOpen}
onOpen={toggleIsSidekickMenuOpen}
onClose={toggleIsSidekickMenuOpen}
open={isHeartMenuOpen}
onOpen={toggleIsHeartMenuOpen}
onClose={toggleIsHeartMenuOpen}
actions={[
{
items: [{content: 'Light theme popover'}],
Expand Down Expand Up @@ -86,7 +86,7 @@ export function Default() {
<TopBar
secondaryMenu={
<InlineStack>
{sidekickMenu}
{heartMenu}
{notificationsMenu}
</InlineStack>
}
Expand Down
14 changes: 10 additions & 4 deletions polaris-tokens/scripts/toStyleSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ export function getMetaTokenGroupDecls(metaTokenGroup: MetaTokenGroupShape) {
MetaTokenGroupShape[string],
];

return tokenName.startsWith('motion-keyframes')
? `${createVarName(tokenName)}:p-${tokenName};`
: `${createVarName(tokenName)}:${value};`;
if (tokenName.startsWith('color-scheme')) {
return `color-scheme:${value};`;
}

if (tokenName.startsWith('motion-keyframes')) {
return `${createVarName(tokenName)}:p-${tokenName};`;
}

return `${createVarName(tokenName)}:${value};`;
})
.join('');
}
Expand Down Expand Up @@ -68,7 +74,7 @@ export async function toStyleSheet() {
const styles = [
[
`:root,${createThemeSelector(themeNameDefault)}`,
`{color-scheme:light;${getMetaThemeDecls(metaThemeDefault)}}`,
`{${getMetaThemeDecls(metaThemeDefault)}}`,
].join(''),
metaThemePartialsEntries.map(
([themeName, metaThemePartial]) =>
Expand Down
4 changes: 4 additions & 0 deletions polaris-tokens/src/themes/base/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export type ColorTextAlias =
| 'video-thumbnail-play-button-text-on-bg-fill';

export type ColorTokenName =
| 'color-scheme'
| `color-${ColorBackgroundAlias}`
| `color-${ColorBorderAlias}`
| `color-${ColorIconAlias}`
Expand All @@ -253,6 +254,9 @@ export type ColorTokenGroup = {
export const color: {
[TokenName in ColorTokenName]: MetaTokenProperties;
} = {
'color-scheme': {
value: 'light',
},
'color-bg': {
value: colors.gray[6],
description: 'The default background color of the admin.',
Expand Down
1 change: 1 addition & 0 deletions polaris-tokens/src/themes/dark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {createMetaTheme, createMetaThemePartial} from './utils';

export const metaThemeDarkPartial = createMetaThemePartial({
color: {
'color-scheme': {value: 'dark'},
'color-bg': {value: colors.gray[16]},
'color-bg-surface': {value: colors.gray[15]},
'color-bg-fill': {value: colors.gray[15]},
Expand Down
25 changes: 24 additions & 1 deletion polaris-tokens/tests/toStyleSheet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,22 @@ const mockMotionTokenGroup = {
value: 'valueD',
},
};

const mockColorTokenGroup = {
'color-scheme': {
value: 'light',
},
'color-token-1': {
value: 'valueA',
},
'color-token-2': {
value: 'valueB',
},
};

const mockTheme = {
tokenGroupName: mockTokenGroup,
color: mockColorTokenGroup,
motion: mockMotionTokenGroup,
};

Expand All @@ -38,7 +52,10 @@ const expectedTokenGroupDecls =
const expectedMotionTokenGroupDecls =
'--p-motion-token-1:valueA;--p-motion-token-2:valueB;--p-motion-keyframes-token-1:p-motion-keyframes-token-1;--p-motion-keyframes-token-2:p-motion-keyframes-token-2;';

const expectedThemeDecls = `${expectedTokenGroupDecls}${expectedMotionTokenGroupDecls}`;
const expectedColorTokenGroupDecls =
'color-scheme:light;--p-color-token-1:valueA;--p-color-token-2:valueB;';

const expectedThemeDecls = `${expectedTokenGroupDecls}${expectedColorTokenGroupDecls}${expectedMotionTokenGroupDecls}`;

const expectedMotionKeyframes =
'@keyframes p-motion-keyframes-token-1valueC@keyframes p-motion-keyframes-token-2valueD';
Expand All @@ -55,6 +72,12 @@ describe('getMetaTokenGroupDecls', () => {

expect(tokenGroupDecls).toBe(expectedMotionTokenGroupDecls);
});

it('creates a string of CSS declarations from color tokens', () => {
const tokenGroupDecls = getMetaTokenGroupDecls(mockColorTokenGroup);

expect(tokenGroupDecls).toBe(expectedColorTokenGroupDecls);
});
});

describe('getKeyframes', () => {
Expand Down

0 comments on commit b6fe014

Please sign in to comment.