Skip to content

Commit

Permalink
Merge branch 'main' into update/minimizable-dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
shleewhite committed Feb 27, 2023
2 parents dedae1d + b942178 commit 679daeb
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .changeset/empty-mayflies-cry.md
@@ -0,0 +1,6 @@
---
'@twilio-paste/theme': patch
'@twilio-paste/core': patch
---

[Theme] Add theme override via url by using `#paste-theme-override=[newtheme]`.
3 changes: 1 addition & 2 deletions .github/DISCUSSION_TEMPLATE/office-hours-data-growth.yml
@@ -1,5 +1,4 @@
title: "Office hours"
description: "Questions and discussion topics for office hours"
title: ""
body:
- type: "textarea"
id: "background"
Expand Down
3 changes: 1 addition & 2 deletions .github/DISCUSSION_TEMPLATE/office-hours-visual-design.yml
@@ -1,5 +1,4 @@
title: "Office hours"
description: "Questions and discussion topics for office hours"
title: ""
body:
- type: "textarea"
id: "background"
Expand Down
2 changes: 1 addition & 1 deletion .github/DISCUSSION_TEMPLATE/office-hours.yml
@@ -1,4 +1,4 @@
title: "Office hours"
title: ""
body:
- type: "textarea"
id: "background"
Expand Down
2 changes: 1 addition & 1 deletion .github/DISCUSSION_TEMPLATE/request-icon.yml
@@ -1,4 +1,4 @@
title: "Icon request"
title: ""
body:
- type: textarea
id: "description"
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/on_pull_request.yml
Expand Up @@ -303,6 +303,9 @@ jobs:
name: Storybook test runner
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
shard: [1/4, 2/4, 3/4, 4/4]
steps:
- name: Checkout Repo
uses: actions/checkout@v3
Expand Down Expand Up @@ -360,7 +363,7 @@ jobs:
run: npx playwright install --with-deps

- name: Run Storybook test runner
run: yarn start:test:storybook
run: yarn start-server-and-test 'NODE_ENV=test yarn start:storybook' http://localhost:9001 'yarn test:storybook --shard=${{ matrix.shard }}'

prettier:
name: Prettier checks
Expand Down
2 changes: 1 addition & 1 deletion .storybook/preview.tsx
Expand Up @@ -22,7 +22,7 @@ export const globalTypes = {
// https://github.com/storybookjs/storybook/blob/master/lib/components/src/icon/icons.tsx
icon: 'paintbrush',
// array of plain string values or MenuItem shape (see below)
items: ['default', 'dark', 'sendgrid', 'twilio', 'twilio-dark'],
items: ['default', 'dark', 'sendgrid', 'evergreen', 'twilio', 'twilio-dark'],
},
},
theme_layout: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -136,7 +136,7 @@
"@storybook/cli": "7.0.0-beta.45",
"@storybook/react": "7.0.0-beta.45",
"@storybook/react-vite": "7.0.0-beta.45",
"@storybook/test-runner": "0.9.1",
"@storybook/test-runner": "0.9.3",
"@storybook/testing-library": "0.0.13",
"@swc/core": "^1.2.160",
"@swc/jest": "^0.2.20",
Expand Down
Expand Up @@ -152,7 +152,7 @@ props:

# overlay backgrounds
color-background-overlay:
value: "#4D4D66"
value: "#4D4D6664"
comment: Default background for overlays.

#availability
Expand Down
16 changes: 16 additions & 0 deletions packages/paste-theme/__tests__/themeProvider.spec.tsx
Expand Up @@ -35,6 +35,22 @@ describe('Theme.Provider', () => {
expect(getByText('Color: rgb(2, 99, 224)')).toBeDefined();
});

it('should override selected theme with hash value', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete window.location;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.location = new URL('https://www.example.com#paste-theme-override=evergreen');

const {getByText} = render(
<Theme.Provider>
<ThemeConsumerExampleTextColor />
</Theme.Provider>
);
expect(getByText('Color: rgb(51, 102, 255)')).toBeDefined();
});

it('should rely on the default breakpoints set on the theme object', () => {
const {getByText} = render(
<Theme.Provider theme="default">
Expand Down
22 changes: 21 additions & 1 deletion packages/paste-theme/src/themeProvider.tsx
Expand Up @@ -9,6 +9,7 @@ import {
} from '@twilio-paste/styling-library';
import type {CreateCacheOptions} from '@twilio-paste/styling-library';

import {getThemeFromHash} from './utils/getThemeFromHash';
import {DefaultTheme, SendGridTheme, DarkTheme, TwilioTheme, TwilioDarkTheme, EvergreenTheme} from './themes';
import {pasteGlobalStyles} from './styles/global';
import {pasteBaseStyles} from './styles/base';
Expand All @@ -17,6 +18,24 @@ import {ThemeVariants} from './constants';

export const StyledBase = styled.div(pasteBaseStyles);

const useThemeOverwriteHook = (): string | undefined => {
const [overwriteTheme, setOverwriteTheme] = React.useState(getThemeFromHash());

const handleLocationChange = (): void => {
setOverwriteTheme(getThemeFromHash());
};

React.useEffect(() => {
window.addEventListener('popstate', handleLocationChange);

return () => {
window.removeEventListener('popstate', handleLocationChange);
};
});

return overwriteTheme;
};

// eslint-disable-next-line @typescript-eslint/ban-types
function getProviderThemeProps(theme: ThemeVariants, customBreakpoints?: string[]): {} {
switch (theme) {
Expand Down Expand Up @@ -76,8 +95,9 @@ const ThemeProvider: React.FunctionComponent<React.PropsWithChildren<ThemeProvid
skipAnimation: disableAnimations || prefersReducedMotion,
});
}, [disableAnimations, prefersReducedMotion]);
const overwriteTheme = useThemeOverwriteHook();

const providerThemeProps = getProviderThemeProps(theme, customBreakpoints);
const providerThemeProps = getProviderThemeProps(overwriteTheme || theme, customBreakpoints);

if (cache) {
return (
Expand Down
9 changes: 9 additions & 0 deletions packages/paste-theme/src/utils/getThemeFromHash.ts
@@ -0,0 +1,9 @@
export const getThemeFromHash = (): string | undefined => {
try {
if (window.location.hash.includes('paste-theme-override')) {
return window.location.hash.split('=')[1];
}
// eslint-disable-next-line unicorn/prefer-optional-catch-binding
} catch (error) {}
return undefined;
};
Expand Up @@ -108,7 +108,7 @@ Callouts can have lists of information within them. Use the `CalloutList` and `C
<CalloutHeading>
Make sure to check for personal data, such as:
</CalloutHeading>
<CalloutList>
<CalloutList as="ul">
<CalloutListItem>Name</CalloutListItem>
<CalloutListItem>Email</CalloutListItem>
<CalloutListItem>Phone number</CalloutListItem>
Expand Down
2 changes: 1 addition & 1 deletion packages/paste-website/src/pages/components/index.mdx
Expand Up @@ -44,7 +44,7 @@ export const getStaticProps = async () => {

<Callout variant="neutral" marginY="space70">
<CalloutHeading as="h2">Don't see a component, primitive, or layout you need listed here?</CalloutHeading>
<CalloutList>
<CalloutList as="ul">
<CalloutListItem>
First off, we recommend <SiteLink href="/roadmap">checking our roadmap</SiteLink>.
</CalloutListItem>
Expand Down
2 changes: 1 addition & 1 deletion packages/paste-website/src/pages/primitives/index.mdx
Expand Up @@ -41,7 +41,7 @@ export const getStaticProps = async () => {

<Callout variant="neutral" marginY="space70">
<CalloutHeading as="h2">Don't see a primitive, layout, or component you need listed here?</CalloutHeading>
<CalloutList>
<CalloutList as="ul">
<CalloutListItem>
First off, we recommend <SiteLink href="/roadmap">checking our roadmap</SiteLink>.
</CalloutListItem>
Expand Down
Expand Up @@ -218,7 +218,7 @@ This package is a wrapper around the [Reakit Composite](https://reakit.io/docs/c
#### Installation

```bash
yarn add @twilio-paste/listbox-primitve - or - yarn add @twilio-paste/core
yarn add @twilio-paste/listbox-primitive - or - yarn add @twilio-paste/core
```

#### Props
Expand Down
Expand Up @@ -179,7 +179,7 @@ This package is a wrapper around the [Reakit Menu](https://reakit.io/docs/menu/)
#### Installation

```bash
yarn add @twilio-paste/menu-primitve - or - yarn add @twilio-paste/core
yarn add @twilio-paste/menu-primitive - or - yarn add @twilio-paste/core
```

#### Props
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Expand Up @@ -9892,9 +9892,9 @@ __metadata:
languageName: node
linkType: hard

"@storybook/test-runner@npm:0.9.1":
version: 0.9.1
resolution: "@storybook/test-runner@npm:0.9.1"
"@storybook/test-runner@npm:0.9.3":
version: 0.9.3
resolution: "@storybook/test-runner@npm:0.9.3"
dependencies:
"@babel/core": ^7.18.13
"@babel/generator": ^7.18.13
Expand Down Expand Up @@ -9927,7 +9927,7 @@ __metadata:
ts-dedent: ^2.0.0
bin:
test-storybook: bin/test-storybook.js
checksum: de2bf0866adb2fff854f6dfcd7e3904b14326bc8c3f0f137eaa20ad76bc15365443f949cd4299918c34177de4cadb002ffc8825f0dccd669bb95722085c9f645
checksum: 665dfddd8b18005b9b0203115e35585410fbbcbcccd9ff220e18914e1131c88898216b468a4ed5d956ceefe2ca1a38d88d22b10b445be0dedb89a19c5f539bca
languageName: node
linkType: hard

Expand Down Expand Up @@ -37416,7 +37416,7 @@ fsevents@^1.2.7:
"@storybook/cli": 7.0.0-beta.45
"@storybook/react": 7.0.0-beta.45
"@storybook/react-vite": 7.0.0-beta.45
"@storybook/test-runner": 0.9.1
"@storybook/test-runner": 0.9.3
"@storybook/testing-library": 0.0.13
"@swc/core": ^1.2.160
"@swc/jest": ^0.2.20
Expand Down

0 comments on commit 679daeb

Please sign in to comment.