headwayio / shipwright-tokens

Set of scripts for converting shipwright tokens to usable styles.
1 stars 1 forks source link

Shipwright Tokens

Contents


Configure: Filter Actions

Shipwright Tokens is a powerful tool, but you probably don't want it to run for every PR made in your repo. Instead, you likely only want it to run when you've made changes to your design tokens in Figma. This section will show you how to configure your action to run Shipwright Tokens only when you want it.

Add one of the below snippets to your .yml file that uses Shipwright Tokens.

Filter by Branch Name

This method triggers the Shipwright Tokens action to run whenever a PR is opened from a branch name beginning with tokens/. If you want another naming convention in your project, simply replace tokens with your preferred name. Using this method, you will need to ensure that you are making commits to a branch beginning with tokens/, or your prefered naming convention, from within the Figma Tokens Plug-in.

on:
 push:
   branches:
     - 'tokens/**'

Filter by Directory/Files Changed

This method triggers the Shipwright Tokens action when a PR is opened that contains changes to any file in the tokens directory. If you are saving your tokens in a different directory, replace tokens with the path to/name of your directory.

on:
 pull_request:
   paths:
     - 'tokens/**'

You can further specify which branch the PR is made against if you'd like to. The below example will trigger the Shipwright Token action when a PR is made against main while also containing changes to files in the tokens directory.

on:
 pull_request:
   paths:
     - 'tokens/**'
   branches:
     - 'main'

Default Behavior

Using the provided template, without configuring the filter actions, will cause the Shipwright Tokens action to run on any PR opened against main.


Integrate Tailwind CSS

This section will show you how to configure your Shipwright Tokens action to output a custom Tailwind CSS theme.

Generate a Custom Theme

Ensure that the .yml file that calls Shipwright Tokens includes tailwind as the value for the styleSystem property:

    steps:
      - name: Shipwright Tokens
        uses: headwayio/shipwright-tokens@(release/version)
        with:
          styleSystem: tailwind

With this configuration option set, Shipwright Tokens will generate 5 files that will be used for your custom theme: tailwind.config.js, colors.json, misc.json, shadows.json, and typography.json. These files will be generated in the directory that you specify for the outputFolder property.

Using the Custom Theme

By default, the generated tailwind.config.js file will import and extend the 4 generated .json files, making all styles in your custom theme available as a base for your existing tailwing config. To incorporate the generated theme with your existing tailwind config, add the following snippet to module.exports within your projects existing tailwind.config.js file:

  presets: [
    require('yourOutputDirectory/tailwind.config.js')
  ],

If your project does not have an existing tailwind config, move the generated tailwing.config.js file to the root directory of your project and update the import paths to the generated .json files.

You can pick and choose which styles are available in your project by editing the generated tailwind.config.js to only include the styles you want, the two sections below will show you how to do this.

Colors, Shadows, and Misc styles:

const colors = require("./yourOutputDirectory/colors");
const shadows = require("./yourOutputDirectory/shadows");
const misc = require("./yourOutputDirectory/misc");
  theme: {
    extend: {
      colors,
      shadows,
      ...misc,
    },
  },

Typography:

const typography = require("./yourOutputDirectory/typography");
const plugin = require("tailwindcss/plugin");
plugins: [
    plugin(function ({ addBase, addComponents }) {
      addComponents({
        ...typography,
      });
    }),
  ],

Integrate MUI

This section will show you how to configure your Shipwright Tokens action to output a custom MUI theme.

Generate a Custom Theme

Ensure that the .yml file that calls Shipwright Tokens includes mui as the value for the styleSystem property:

    steps:
      - name: Shipwright Tokens
        uses: headwayio/shipwright-tokens@(release/version)
        with:
          styleSystem: mui

With this configuration option set, Shipwright Tokens will generate 5 files that will be used for your custom theme: muiTheme.js, colors.json, misc.json, shadows.json, and typography.json. These files will be generated in the directory that you specify for the outputFolder property.

Using the Custom Theme

By default, the generated muiTheme.js file will import and extend the 4 generated .json files, making all styles in your custom theme available for use. To start using your custom theme, you simply need to pass your custom theme to MUI's ThemeProvider component by doing the following:

import theme from "./yourOutputDirectory/muiTheme";
      <ThemeProvider theme={theme}>
        <Component {...pageProps} />
      </ThemeProvider>

Pick and Choose Styles

You can pick and choose which styles are availble in your project by editing the generated muiTheme.js to only include the styles you want by adding/removing the following snippets:

Colors:

const palette = require("./yourOutputDirectory/colors");
const theme = createTheme({
  palette,
});

Shadows:

const shadows = require("./yourOutputDirectory/shadows");
const theme = createTheme({
  shadows,
});

Typography:

const typography = require("./typography");
const misc = require("./misc");
const theme = createTheme({
  typography: {
    ...typography,
    ...misc,
  },
});

Integrate Restyle

This section will show you how to configure your Shipwright Tokens action to output a custom React Native Restyle theme.

Generate a Custom Theme

Ensure that the .yml file that calls Shipwright Tokens includes restyle as the value for the styleSystem property:

    steps:
      - name: Shipwright Tokens
        uses: headwayio/shipwright-tokens@(release/version)
        with:
          styleSystem: restyle

With this configuration option set, Shipwright Tokens will generate 5 files that will be used for your custom theme: restyleTheme.js, colors.json, misc.json, shadows.json, and typography.json. These files will be generated in the directory that you specify for the outputFolder property.

Using the Custom Theme

By default, the generated restyleTheme.ts file will import and extend the 4 generated .json files, making all styles in your custom theme available for use. To start using your custom theme, you simply need to pass your custom theme to Restyle's ThemeProvider component by doing the following:

import shipwrightTheme from "./styles/restyleTheme";

const theme = {
  ...shipwrightTheme,
  textVariants: {
    ...shipwrightTheme.textVariants,
    defaults: {
      fontSize: "16",
    },
  },
};

export type Theme = typeof theme;
export default theme;
import theme from "./theme";
      <ThemeProvider theme={theme}>
        <Component {...pageProps} />
      </ThemeProvider>

Pick and Choose Styles

You can pick and choose which styles are availble in your project by editing the generated restyleTheme.ts to only include the styles you want by adding/removing the following snippets:

Colors:

const palette = require("./yourOutputDirectory/colors");
const theme = createTheme({
  colors: {
      primaryMain: palette.primary.main,
      primaryDark: palette.primary.dark,
      primaryLight: palette.primary.light,
      secondaryMain: palette.secondary.main,
      secondaryDark: palette.secondary.dark,
      secondaryLight: palette.secondary.light
      }
});

Shadows:

const shadows = require("./yourOutputDirectory/shadows");
const theme = createTheme({
  shadows: {
    ...shadows
  }
});

Typography:

const typography = require("./typography");
const theme = createTheme({
  textVariants: {
    ...typography
  }
});