Skip to content

Commit

Permalink
[ThemeProvider] Change frameOffset to accept string
Browse files Browse the repository at this point in the history
  • Loading branch information
kyledurand committed Jan 19, 2021
1 parent 1a5ae98 commit 638d66c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 18 deletions.
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f

- Remove `light` property from `Tooltip` as it now defaults to a light background ([#3803](https://github.com/Shopify/polaris-react/pull/3803)) ([#3803](https://github.com/Shopify/polaris-react/pull/3803))
- Made `title` property required in `Modal` for accessibility label, added `hideTitle` property ([#3803](https://github.com/Shopify/polaris-react/pull/3803)) ([#3803](https://github.com/Shopify/polaris-react/pull/3803))
- Changed the `frameOffset` prop to accept a string in `ThemeProvider` ([]())

### Enhancements

Expand Down
2 changes: 1 addition & 1 deletion src/components/Frame/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ function FrameExample() {
background: '#225062',
},
},
frameOffset: 60,
frameOffset: '60px',
logo: {
width: 124,
topBarSource:
Expand Down
16 changes: 3 additions & 13 deletions src/utilities/theme/tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('buildCustomProperties', () => {
expect(colors).not.toContain('--top-bar-background');
});

it('creates default custom property of 0px for frameOffset when frameOffset is undefined and newDesignLanguage is false', () => {
it('creates default custom property of 0px for frameOffset when frameOffset is undefined', () => {
const theme = {
colors: {topBar: {background: '#eeeeee'}, surface: '#ffffff'},
colorScheme: DefaultColorScheme,
Expand All @@ -132,19 +132,9 @@ describe('buildCustomProperties', () => {
expect(colors).toMatchObject({'--p-frame-offset': '0px'});
});

it('creates default custom property of 0px for frameOffset when frameOffset is undefined and newDesignLanguage is true', () => {
const theme = {
colors: {topBar: {background: '#eeeeee'}, surface: '#ffffff'},
colorScheme: DefaultColorScheme,
};

const colors = buildCustomProperties(theme, true);
expect(colors).toMatchObject({'--p-frame-offset': '0px'});
});

it('creates custom property with value for frameOffset when frameOffset is provided and newDesignLanguage is false', () => {
const theme = {
frameOffset: 60,
frameOffset: '60px',
colors: {topBar: {background: '#eeeeee'}, surface: '#ffffff'},
colorScheme: DefaultColorScheme,
};
Expand All @@ -155,7 +145,7 @@ describe('buildCustomProperties', () => {

it('creates custom property with value for frameOffset when frameOffset is provided and newDesignLanguage is true', () => {
const theme = {
frameOffset: 80,
frameOffset: '80px',
colors: {topBar: {background: '#eeeeee'}, surface: '#ffffff'},
colorScheme: DefaultColorScheme,
};
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/theme/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface ThemeConfig {
colors?: Partial<RoleColors> & LegacyColors;
colorScheme?: ColorScheme;
config?: Config;
frameOffset?: number;
frameOffset?: string;
}

export type CustomPropertiesLike = Record<string, string>;
Expand Down
6 changes: 3 additions & 3 deletions src/utilities/theme/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ export function buildCustomPropertiesNoMemo(
newDesignLanguage: boolean,
tokens?: Record<string, string>,
): CustomPropertiesLike {
const {colors = {}, colorScheme, config, frameOffset = 0} = themeConfig;
const {colors = {}, colorScheme, config, frameOffset = '0px'} = themeConfig;
const mergedConfig = mergeConfigs(base, config || {});

return newDesignLanguage
? customPropertyTransformer({
...colorFactory(colors, colorScheme, mergedConfig),
...tokens,
frameOffset: `${frameOffset}px`,
frameOffset,
})
: {
...buildLegacyColors(themeConfig),
...customPropertyTransformer({frameOffset: `${frameOffset}px`}),
...customPropertyTransformer({frameOffset}),
};
}

Expand Down

0 comments on commit 638d66c

Please sign in to comment.