Skip to content

Commit e0adb01

Browse files
kyledurandlaurkim
authored andcommitted
Add global class and scss helper (#9238)
Help with toggling between current and se23 Toggles a class on the document root that we can hook into via a handy sass var: ```scss #{$se23} & { --pc-button-color: var(--p-text); } ``` --------- Co-authored-by: Lo Kim <lo.kim@shopify.com>
1 parent d98061f commit e0adb01

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

polaris-react/src/components/AppProvider/AppProvider.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import {
1515
} from '../../utilities/sticky-manager';
1616
import {LinkContext} from '../../utilities/link';
1717
import type {LinkLikeComponent} from '../../utilities/link';
18-
import {FeaturesContext} from '../../utilities/features';
18+
import {
19+
FeaturesContext,
20+
summerEditions2023ClassName,
21+
} from '../../utilities/features';
1922
import type {FeaturesConfig} from '../../utilities/features';
2023

2124
import './AppProvider.scss';
@@ -59,6 +62,7 @@ export class AppProvider extends Component<AppProviderProps, State> {
5962
if (document != null) {
6063
this.stickyManager.setContainer(document);
6164
this.setBodyStyles();
65+
this.setRootAttributes();
6266
}
6367
}
6468

@@ -68,6 +72,8 @@ export class AppProvider extends Component<AppProviderProps, State> {
6872
}: AppProviderProps) {
6973
const {i18n, linkComponent} = this.props;
7074

75+
this.setRootAttributes();
76+
7177
if (i18n === prevI18n && linkComponent === prevLinkComponent) {
7278
return;
7379
}
@@ -83,6 +89,13 @@ export class AppProvider extends Component<AppProviderProps, State> {
8389
document.body.style.color = 'var(--p-color-text)';
8490
};
8591

92+
setRootAttributes = () => {
93+
document.documentElement.classList.toggle(
94+
summerEditions2023ClassName,
95+
this.props.features?.polarisSummerEditions2023,
96+
);
97+
};
98+
8699
render() {
87100
const {
88101
children,

polaris-react/src/components/Button/Button.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@
213213
--pc-button-color-hover: var(--p-color-bg-primary-hover);
214214
--pc-button-color-active: var(--p-color-bg-primary-active);
215215
--pc-button-color-depressed: var(--p-color-bg-primary-active);
216+
217+
#{$se23} & {
218+
--pc-button-color: var(--p-text);
219+
}
216220
// stylelint-enable
221+
217222
svg {
218223
fill: var(--p-color-icon-on-color);
219224
}

polaris-react/src/styles/_common.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717
@import './shared/interaction-state';
1818

1919
@import '../../../node_modules/@shopify/polaris-tokens/dist/scss/media-queries';
20+
21+
$se23: "html[class*='Polaris-Summer-Editions-2023']";

polaris-react/src/utilities/features/context.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {createContext} from 'react';
22

33
import type {FeaturesConfig} from './types';
44

5+
export const summerEditions2023ClassName = 'Polaris-Summer-Editions-2023';
6+
57
export const FeaturesContext = createContext<FeaturesConfig | undefined>(
68
undefined,
79
);

0 commit comments

Comments
 (0)