Skip to content

Commit 3662d5a

Browse files
Luke BowermanLuke Bowerman
authored andcommitted
Include GlobalStyle within ComponentsProvider
While building out a sandbox prototype it occured to me that we could encapsulate GlobalStyles within our default provider and simplify the setup process by one more step :)
1 parent 150d140 commit 3662d5a

File tree

10 files changed

+29
-12
lines changed

10 files changed

+29
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- `ActionList` documentation
13+
- `ComponentsProvider` now automatically loads `GlobalStyle` (also provides `globalStyle={false}` prop to disable this behavior)
1314

1415
### Changed
1516

packages/components/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export * from './Chip'
3535
export * from './DateTimeFormat'
3636
export * from './Divider'
3737
export * from './Form'
38-
export * from './GlobalStyle'
3938
export * from './Icon'
4039
export * from './Layout'
4140
export * from './Link'
@@ -62,6 +61,7 @@ export { ComponentsProvider } from '@looker/components-providers'
6261
**/
6362

6463
export {
64+
GlobalStyle,
6565
palette,
6666
radii,
6767
semanticColors,
File renamed without changes.
File renamed without changes.

packages/design-tokens/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
export * from './system'
2828
export * from './theme'
2929

30+
export * from './GlobalStyle'
31+
3032
export { palette, radii, semanticColors } from './tokens'
3133

3234
// Useful external helpers

packages/playground/src/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@
2626

2727
import React from 'react'
2828
import ReactDOM from 'react-dom'
29-
import { ComponentsProvider, GlobalStyle } from '@looker/components'
29+
import { ComponentsProvider } from '@looker/components'
3030
import { FieldsDemo } from './Form/FieldsDemo'
3131

3232
const App: React.FC = () => {
3333
return (
3434
<ComponentsProvider>
35-
<GlobalStyle />
3635
<FieldsDemo />
3736
</ComponentsProvider>
3837
)

packages/providers/src/ComponentsProvider.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
SOFTWARE.
2424
2525
*/
26+
27+
import { GlobalStyle } from '@looker/design-tokens'
2628
import React, { FC } from 'react'
2729
import { ThemeProvider, ThemeProviderProps } from './ThemeProvider'
2830

@@ -33,8 +35,21 @@ import { ThemeProvider, ThemeProviderProps } from './ThemeProvider'
3335
*/
3436

3537
// eslint-disable-next-line @typescript-eslint/no-empty-interface
36-
export interface ComponentsProviderProps extends ThemeProviderProps {}
37-
38-
export const ComponentsProvider: FC<ComponentsProviderProps> = (props) => (
39-
<ThemeProvider {...props} />
38+
export interface ComponentsProviderProps extends ThemeProviderProps {
39+
/**
40+
* Prevent automatic injection of a basic CSS-reset into the DOM
41+
* @default true
42+
*/
43+
globalStyle?: boolean
44+
}
45+
46+
export const ComponentsProvider: FC<ComponentsProviderProps> = ({
47+
children,
48+
globalStyle = true,
49+
...props
50+
}) => (
51+
<ThemeProvider {...props}>
52+
{globalStyle && <GlobalStyle />}
53+
{children}
54+
</ThemeProvider>
4055
)

packages/www/src/Layout/Page.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
*/
2626

2727
import {
28-
GlobalStyle,
2928
ComponentsProvider,
3029
CustomizableTooltipAttributes,
3130
} from '@looker/components'
@@ -45,10 +44,7 @@ const Page: FC = ({ children }) => {
4544
href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&display=swap"
4645
rel="stylesheet"
4746
/>
48-
<MDXProvider components={all}>
49-
<GlobalStyle />
50-
{children}
51-
</MDXProvider>
47+
<MDXProvider components={all}>{children}</MDXProvider>
5248
</ComponentsProvider>
5349
)
5450
}

packages/www/src/documentation/getting-started/index.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ echo '@types/react-native' > .yarnclean
3737

3838
At the top-most level of the usage of `@looker/components` you need to load the `<GlobalStyle />` component. This will inject a simple CSS reset as well as basic font assignment. [GlobalStyle documentation &rarr;](/utilities/globalstyle)
3939

40+
NOTE: The `ComponentsProvider` will automatically load the `GlobalStyle` component for you.
41+
4042
### Web Font Loading
4143

4244
Users may not have the `@looker/components` default font, Open Sans, installed on their computers so we recommend importing the font to ensure that content is rendered with the proper font-face.

packages/www/src/documentation/utilities/globalstyle.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ This component provides a basic set of styles to enable Looker Components. While
88

99
`GlobalStyle` will apply style broadly and may have impacts on other content. In the future we will provide a way to scope the GlobalStyle to only apply to HTML output by `@looker/components` but for the time-being the assumption is that the CSS applied is narrow in it's behavior and should have limited side-effects.
1010

11+
NOTE: The `ComponentsProvider` will automatically load the `GlobalStyle` component for you.
12+
1113
It's composed of two primary pieces:
1214

1315
## Default Font

0 commit comments

Comments
 (0)