Skip to content

Commit

Permalink
feat(theme): add the console theme and update default theme
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Theme provider default theme is now DEFAULT, not CONSOLE. If you are not providing a theme prop but want the console theme you must now explicitly set the theme to console
  • Loading branch information
SiTaggart committed Dec 19, 2019
1 parent 3ee6b5d commit 3951f82
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 23 deletions.
16 changes: 6 additions & 10 deletions packages/paste-theme/README.md
Expand Up @@ -11,9 +11,7 @@ You should place the `Theme.Provider` around the root of your React application.
```js ```js
import {Theme} from '@twilio-paste/theme'; import {Theme} from '@twilio-paste/theme';


<Theme.Provider> <Theme.Provider theme="console">...</Theme.Provider>;
...
</Theme.Provider>
``` ```


## Using tokens in custom components ## Using tokens in custom components
Expand All @@ -33,7 +31,7 @@ import {themeGet} from '@styled-system/theme-get';
const custom = styled.div` const custom = styled.div`
background-color: ${themeGet('backgrounds.primary')}; background-color: ${themeGet('backgrounds.primary')};
padding: ${props => props.theme.spacing.spacing20}; padding: ${props => props.theme.spacing.spacing20};
` `;
``` ```


### Paste ThemeConsumer ### Paste ThemeConsumer
Expand All @@ -47,7 +45,7 @@ import {Theme} from '@twilio-paste/theme';
{({theme}) => { {({theme}) => {
return <p>What is the default text color {theme.textColors.colorText}</p>; return <p>What is the default text color {theme.textColors.colorText}</p>;
}} }}
</Theme.Consumer> </Theme.Consumer>;
``` ```


### Paste useTheme Hook ### Paste useTheme Hook
Expand All @@ -56,7 +54,7 @@ Paste Theme provides a React Hook called `useTheme` which returns the theme obje


```js ```js
import React from 'react'; import React from 'react';
import { useTheme } from '@twilio-paste/theme'; import {useTheme} from '@twilio-paste/theme';


const HookExampleComponent = (): React.ReactElement => { const HookExampleComponent = (): React.ReactElement => {
const theme = useTheme(); const theme = useTheme();
Expand All @@ -70,10 +68,8 @@ Paste also provides a HOC Component, which is a wrapper around the Emotion [HOC


```js ```js
import React from 'react'; import React from 'react';
import { withTheme } from '@twilio-paste/theme'; import {withTheme} from '@twilio-paste/theme';


const ExampleComponent = ({theme}) => ( const ExampleComponent = ({theme}) => <p>What is the default text color {theme.textColors.colorText}</p>;
<p>What is the default text color {theme.textColors.colorText}</p>
);
const ExampleComponentwithTheme = withTheme(ExampleComponent); const ExampleComponentwithTheme = withTheme(ExampleComponent);
``` ```
4 changes: 2 additions & 2 deletions packages/paste-theme/__tests__/themeConsumer.spec.tsx
Expand Up @@ -10,7 +10,7 @@ const ThemeConsumerExampleComponent = (): React.ReactElement => {
describe('Theme.Consumer', () => { describe('Theme.Consumer', () => {
it('should render without crashing', (): void => { it('should render without crashing', (): void => {
ReactDOM.render( ReactDOM.render(
<Theme.Provider> <Theme.Provider theme="console">
<ThemeConsumerExampleComponent /> <ThemeConsumerExampleComponent />
</Theme.Provider>, </Theme.Provider>,
document.createElement('div') document.createElement('div')
Expand All @@ -19,7 +19,7 @@ describe('Theme.Consumer', () => {


it('should be able to access the theme object', () => { it('should be able to access the theme object', () => {
const wrapper = mount( const wrapper = mount(
<Theme.Provider> <Theme.Provider theme="console">
<ThemeConsumerExampleComponent /> <ThemeConsumerExampleComponent />
</Theme.Provider> </Theme.Provider>
); );
Expand Down
4 changes: 2 additions & 2 deletions packages/paste-theme/__tests__/themeProvider.spec.tsx
Expand Up @@ -18,7 +18,7 @@ describe('Theme.Provider', () => {


it('should render the console link text color', (): void => { it('should render the console link text color', (): void => {
const wrapper = mount( const wrapper = mount(
<Theme.Provider> <Theme.Provider theme="console">
<ThemeConsumerExampleTextColor /> <ThemeConsumerExampleTextColor />
</Theme.Provider> </Theme.Provider>
); );
Expand All @@ -36,7 +36,7 @@ describe('Theme.Provider', () => {


it('should rely on the default breakpoints set on the theme object', () => { it('should rely on the default breakpoints set on the theme object', () => {
const wrapper = mount( const wrapper = mount(
<Theme.Provider> <Theme.Provider theme="console">
<ThemeConsumerExampleComponent /> <ThemeConsumerExampleComponent />
</Theme.Provider> </Theme.Provider>
); );
Expand Down
4 changes: 2 additions & 2 deletions packages/paste-theme/__tests__/useTheme.spec.tsx
Expand Up @@ -11,7 +11,7 @@ const HookExampleComponent = (): React.ReactElement => {
describe('useTheme', () => { describe('useTheme', () => {
it('should render without crashing', (): void => { it('should render without crashing', (): void => {
ReactDOM.render( ReactDOM.render(
<Theme.Provider> <Theme.Provider theme="console">
<HookExampleComponent /> <HookExampleComponent />
</Theme.Provider>, </Theme.Provider>,
document.createElement('div') document.createElement('div')
Expand All @@ -20,7 +20,7 @@ describe('useTheme', () => {


it('should be able to access the theme object', () => { it('should be able to access the theme object', () => {
const wrapper = mount( const wrapper = mount(
<Theme.Provider> <Theme.Provider theme="console">
<HookExampleComponent /> <HookExampleComponent />
</Theme.Provider> </Theme.Provider>
); );
Expand Down
4 changes: 2 additions & 2 deletions packages/paste-theme/__tests__/withTheme.spec.tsx
Expand Up @@ -10,7 +10,7 @@ const MockComponentWithTheme = withTheme(MockComponent);
describe('withTheme', () => { describe('withTheme', () => {
it('should render without crashing', (): void => { it('should render without crashing', (): void => {
ReactDOM.render( ReactDOM.render(
<Theme.Provider> <Theme.Provider theme="console">
<MockComponentWithTheme /> <MockComponentWithTheme />
</Theme.Provider>, </Theme.Provider>,
document.createElement('div') document.createElement('div')
Expand All @@ -19,7 +19,7 @@ describe('withTheme', () => {


it('should be able to access the theme object', () => { it('should be able to access the theme object', () => {
const wrapper = mount( const wrapper = mount(
<Theme.Provider> <Theme.Provider theme="console">
<MockComponentWithTheme /> <MockComponentWithTheme />
</Theme.Provider> </Theme.Provider>
); );
Expand Down
10 changes: 6 additions & 4 deletions packages/paste-theme/src/themeProvider.tsx
Expand Up @@ -3,7 +3,7 @@ import styled from '@emotion/styled';
import {Global, css, SerializedStyles} from '@emotion/core'; import {Global, css, SerializedStyles} from '@emotion/core';
import {themeGet} from '@styled-system/theme-get'; import {themeGet} from '@styled-system/theme-get';
import {ThemeProvider as StyledThemeProvider} from 'emotion-theming'; import {ThemeProvider as StyledThemeProvider} from 'emotion-theming';
import {DefaultTheme, SendGridTheme} from '@twilio-paste/theme-tokens'; import {DefaultTheme, SendGridTheme, ConsoleTheme} from '@twilio-paste/theme-tokens';
import {ThemeVariants} from './constants'; import {ThemeVariants} from './constants';


interface GlobalStyleProps { interface GlobalStyleProps {
Expand Down Expand Up @@ -40,8 +40,7 @@ export interface ThemeProviderProps {


const ThemeProvider: React.FunctionComponent<ThemeProviderProps> = ({ const ThemeProvider: React.FunctionComponent<ThemeProviderProps> = ({
customBreakpoints, customBreakpoints,
// theme = 'console' | 'sendgrid' | 'flex' & 'default' eventually theme = ThemeVariants.DEFAULT,
theme = ThemeVariants.CONSOLE,
...props ...props
}) => { }) => {
let breakpoints = {}; let breakpoints = {};
Expand All @@ -52,8 +51,11 @@ const ThemeProvider: React.FunctionComponent<ThemeProviderProps> = ({
themeObject = SendGridTheme; themeObject = SendGridTheme;
breakpoints = customBreakpoints || SendGridTheme.breakpoints; breakpoints = customBreakpoints || SendGridTheme.breakpoints;
break; break;
case ThemeVariants.FLEX:
case ThemeVariants.CONSOLE: case ThemeVariants.CONSOLE:
themeObject = ConsoleTheme;
breakpoints = customBreakpoints || ConsoleTheme.breakpoints;
break;
case ThemeVariants.FLEX:
case ThemeVariants.DEFAULT: case ThemeVariants.DEFAULT:
default: default:
themeObject = DefaultTheme; themeObject = DefaultTheme;
Expand Down
2 changes: 1 addition & 1 deletion packages/paste-theme/stories/index.stories.tsx
Expand Up @@ -28,7 +28,7 @@ storiesOf('Overview|Theme', module)
}, },
}) })
.add('Provider', () => ( .add('Provider', () => (
<Theme.Provider> <Theme.Provider theme="console">
<p>Using the Theme Provider to wrap your app</p> <p>Using the Theme Provider to wrap your app</p>
</Theme.Provider> </Theme.Provider>
)) ))
Expand Down

0 comments on commit 3951f82

Please sign in to comment.