autoguru-au/overdrive
์๊ฐ
๐๐จ AutoGuru's design system
๋์์ธ ๋ฐ ๋ฏธ๋์ด์ธก์ ๋ ์คํ ์ฆ๊ฐ
- in 24h
- 0
- in 7 days
- ๊ธฐ๋ก ์์ง ์ค
- in 15 days
- ๊ธฐ๋ก ์์ง ์ค
- in 1 month
- ๊ธฐ๋ก ์์ง ์ค
์๋ก ๊ฒน์น๋ ๊ธฐ๊ฐ์ ์์ฆ๊ฐ๋์ด๋ฉฐ ์ผ๋ณ ํฉ๊ณ๊ฐ ์๋๋๋ค. ์ธก์ ๊ฐ์ด ์์ผ๋ฉด ๋น์ ๋ก๋๋ค. ์คํ๋ ๊ด์ฌ๋๋ฅผ ๋ํ๋ด๋ฉฐ ํ์ง์ ๋ณด์ฅํ์ง ์์ต๋๋ค.
README.md
OriginalOverdrive
Overdrive is a product component library, and design system for AutoGuru. Built with React, TypeScript, Vanilla Extract, and Storybook.
The components are housed in Storybook which provides interactive documentation, UI playground, and interaction testing.
Storybook
Visit the Overdrive Storybook site too access foundations, components and API specifications:
overdrive.autoguru.io
Usage
To use Overdrive in your project, install it with Bun:
bun add @autoguru/overdrive react react-dom
Then, import the reset and configure the Overdrive Provider with the theme you want to use:
import { OverdriveProvider, Button } from '@autoguru/overdrive';
<OverdriveProvider>
<Button variant="primary">Hello World</Button>
</OverdriveProvider>;
The Overdrive Provider automatically applies global base styles to the body tag.
If you need more control over where the global base styles are applied, you can
also apply data-od-base to any element.
You can also customise the theme colours using the provider props:
<OverdriveProvider
theme={baseTheme}
colorOverrides={{
primaryBackground: '#FF0000',
primaryForeground: '#FFFFFF',
primaryBackgroundMild: '#FFE5E5',
primaryBackgroundStrong: '#CC0000',
primaryBorder: '#CC0000',
}}
>
<Button variant="primary">Custom Red Theme</Button>
</OverdriveProvider>
Lite provider
OverdriveLiteProvider is a lighter OverdriveProvider for apps whose colours
are fixed when they are built. It supplies the same contexts, theme class and
markup, so components render identically under it, but it does not import the
theme's token values or the colour library behind colorOverrides: theme
colours come from the CSS variables the theme already ships. In a minimal app
that saves about 8 kB of gzipped JavaScript on first load.
import { OverdriveLiteProvider } from '@autoguru/overdrive/components/OverdriveLiteProvider';
import { Button } from '@autoguru/overdrive/components/Button';
<OverdriveLiteProvider>
<Button variant="primary">Hello World</Button>
</OverdriveLiteProvider>;
Use it when the app has no brand colours, or knows them when it is built. Keep
OverdriveProviderwhen brand colours arrive at runtime, for example per tenant from an API.It takes the same
theme,breakpoints,locale,portalMountPointandnoBodyLevelThemingprops. In place ofcolorOverridesit takescolorOverrideStyles, the output ofmakeColorOverrideStyles.Run
makeColorOverrideStylesat build time or on the server, not in the browser, or the colour library comes back. In a vanilla-extract.css.tsfile, import it from@autoguru/overdrive/themes/colorOverrides: a style file pulls in the CSS of everything it imports, and through the main entry that is every component.// brand.css.ts import { makeColorOverrideStyles } from '@autoguru/overdrive/themes/colorOverrides'; export const brandStyles = makeColorOverrideStyles({ primaryBackground: '#6d39a8', });<OverdriveLiteProvider colorOverrideStyles={brandStyles}>On a theme other than the base theme, pass that theme's tokens as the second argument, so contrast is worked out against its own surfaces. Outside a browser it can't check that a colour is valid, so pass valid CSS colours: an invalid one is passed through, where
OverdriveProviderin the browser would drop it with a warning.The saving needs your bundler to leave the full provider out. Vite and Rollup do so from the main entry, though from the uncompiled main entry its theme exports still bring in the base colour palette (about 1 kB gzipped); elsewhere, or to leave that out too, import from deep paths such as
components/OverdriveLiteProvider. ImportingOverdriveProviderorThemeOverrideDebuggeranywhere in the app brings the colour code back. Importing a theme's index oruseDocumentBodyStylesbrings back token values.To use another theme without its token values, pass only what the provider reads:
{ name, themeRef, vars }, withthemeReffrom the theme'stheme.css(for exampleflatRedThemeClass) andvarsset tooverdriveTokensfromthemes/theme.css. Define that object once, outside any component, so it isn't a new theme on every render.useTheme().colorOverridesis alwaysundefinedunder it, soThemeOverrideDebuggerreports the theme's own colours, not a brand passed ascolorOverrideStyles.
Precompiled CSS entry
@autoguru/overdrive ships vanilla-extract style files that compile in your
bundler, so it needs the vanilla-extract plugin for webpack, Vite or Next. If
your bundler or test runner has no such plugin (Bun, bun test, Rolldown,
rspack, esbuild), import from @autoguru/overdrive/compiled instead. Its styles
were compiled when Overdrive was built: the JavaScript only holds class names,
and the CSS is in plain stylesheets you import once at the root of your app.
Rolldown 1.x no longer bundles CSS, so with plain Rolldown load styles.css
outside the bundle, with a <link> or a copy step.
import '@autoguru/overdrive/compiled/reset.css'; // optional, as styles/global/reset.css
import '@autoguru/overdrive/compiled/fonts.css'; // optional, as styles/global/fonts.css
import '@autoguru/overdrive/compiled/styles.css';
import { OverdriveProvider, Button } from '@autoguru/overdrive/compiled';
import { flatRedTheme } from '@autoguru/overdrive/compiled/themes';
<OverdriveProvider theme={flatRedTheme}>
<Button variant="primary">Hello World</Button>
</OverdriveProvider>;
@autoguru/overdrive/compiledhas the same exports and types as@autoguru/overdrive. Themes are on@autoguru/overdrive/compiled/themes.- A few public exports are not on the main entry, only on deep imports. Their
compiled versions are on
@autoguru/overdrive/compiled/components(addsDataTableandModalFooter),@autoguru/overdrive/compiled/styles(addsdarkSurfaceandLAYER_ORDER) and@autoguru/overdrive/compiled/utils(adds the utils index, such asisBrowser,mergeRefsandsetRef). - Other deep imports, such as
components/*,styles/*,themes/*,hooksorutils/*, are not compiled. Most of their names are also on@autoguru/overdrive/compiledor one of the subpaths above, so import them from there. Names only on other deep paths have no compiled version, for exampleHintText,Popover,PopoverTrigger,EAlignment,useRadioContext,dataAttrs, thethemes/makeThemebreakpoint helpers and theutils/dateFormatandutils/numberhelpers. Vanilla-extract authoring helpers, such asresponsiveStyle,focusOutline, the layer names and the sprinkles internals, need a vanilla-extract plugin by nature. styles.cssholds every component, theme and token rule, ordered by the same CSS cascade layers. Theod-token variables andcolorOverrideswork as they do on the main entry.- Nothing touches
windowordocumentat import, so it renders on the server. - Pick one entry per app. Class names differ between the two, so loading both
ships about 316 KB of CSS twice, and both define the global
:roottokens. - Each entry has its own React contexts. Every React tree needs an
OverdriveProviderfrom the same entry as its components; a component under the other entry's provider throws "You haven't used an<OverdriveProvider>". - If you embed compiled components beside a host that uses the main entry,
consider
noBodyLevelThemingon your provider, so the two providers don't both set the theme class ondocument.body.
Thanks
Chromatic for providing visual regression testing.
License
MIT ยฉAutoGuru
๊ด๋ จ ํ๋ก์ ํธ ์ดํด๋ณด๊ธฐ
๋ถ๋ฌ์ค๋ ์คโฆ