Skip to content

Commit

Permalink
Merge pull request #11 from josiahayres/feature/storybook-8
Browse files Browse the repository at this point in the history
Feature/storybook 8
  • Loading branch information
josiahayres committed Mar 13, 2024
2 parents fd11c6e + c69615a commit 17bbad4
Show file tree
Hide file tree
Showing 9 changed files with 8,108 additions and 15,908 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CHROMATIC_PROJECT_TOKEN=
GITHUB_TOKEN=
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ jobs:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Prepare repository
run: git fetch --unshallow --tags

- name: Use Node.js 16.x
uses: actions/setup-node@v3
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 20.x

- name: Install dependencies
run: yarn install --frozen-lockfile --ignore-scripts
Expand Down
20 changes: 17 additions & 3 deletions PUBLISHING_STEPS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Publishing Steps

1. Make code changes
2. `npm run build`
3.
> These are notes for future me, when I've forgotten these steps next time I need to upgrade. May be incomplete.
1. Make code changes on new feature branch

- Manually increase major version in package.json if breaking changes. (eg. `4.0.0-beta.0`).

2. Test it using `npm run start`
3. Once happy check it builds using `npm run build`
4. Push branch to git which should run publish to npm from github action.

- Seems new issue with GH actions (since upgrading to node18), build fails in gh, but runs locally.
- Can manually deploy from local using `npm run publish`.
- Make sure you have a `.env` file created from `.env.example` with required variables.

5. Test beta build on another project, make sure it all works.
6. Remove `.beta-x` from package json version.
7. Merge feature branch into main.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ See [Documentation Page](https://mantine.dev/theming/mantine-provider/#mantinepr

> Most use cases won't need to set anything for this object.
### Color Schemes (Dark/Light Mode) Support.
### Color Schemes (Dark/Light Mode) Support

> Cannot use mantine hooks in addons for storybook v7. Need storybook manager UI to be upgraded to react 18 (so addon can use the useId hook from react). Thi seems [scheduled for Storybook 8 release](https://github.com/storybookjs/storybook/milestone/89).
Expand Down Expand Up @@ -183,15 +183,31 @@ That should be it!

## Versions

This table should help you with picking the correct version of `storybook-addon-mantine`:

| Storybook Version | Mantine Version | storybook-addon-mantine Version |
|:-----------------:|:---------------:|:--------------:|
| 8 | 7 | 4.x |
| 7 | 7 | 3.0.1 |
| 7 | 6 | 2.0.21 |
| 6 | 6 | 1.3 |
| 6 | 5 | 1.2 |
| 6 | 4 | 1.0 |

### 4.0

Only supports [Storybook 8](https://storybook.js.org/blog/storybook-8/) and Mantine 7.

### 3.0

Support Storybook 7.
Support [Mantine v7 Release](https://v7.mantine.dev/guides/6x-to-7x).

These are notable

- [React 18+ Only](https://mantine.dev/changelog/7-0-0/#react-18-only)
- [Color scheme not in theme object](https://mantine.dev/changelog/7-0-0/#built-in-color-scheme-manager)
- [Create theme function](https://mantine.dev/changelog/7-0-0/#createtheme-function
- [Create theme function](<https://mantine.dev/changelog/7-0-0/#createtheme-function>
- [Theme object changes](https://mantine.dev/changelog/7-0-0/#theme-object-changes)

### 2.0
Expand All @@ -202,7 +218,7 @@ These are notable

### 1.3

- Support Mantine v6 (https://mantine.dev/changelog/6-0-0/).
- Support Mantine v6 (<https://mantine.dev/changelog/6-0-0/>).
- Only Require `@mantine/core` as peer dependency

### 1.2
Expand All @@ -211,7 +227,7 @@ These are notable

### 1.1

- Support Mantine v5 (https://mantine.dev/changelog/5-0-0/).
- Support Mantine v5 (<https://mantine.dev/changelog/5-0-0/>).
- Adds second parameter `mantineProviderProps` to `mantineTheme(themesList, mantineProviderProps)`

### 1.0
Expand Down
219 changes: 219 additions & 0 deletions archive-docs/README-v3.x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
# storybook-addon-mantine

Switch between multiple mantine themes without restarting Storybook, and visualise your components / pages with each theme applied.

## How to use

### Install the addon

```shell
npm i -D storybook-addon-mantine
```

### Register the addon

Do this in your project's `.storybook/main.ts` file:

```js
// .storybook/main.ts
import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
// ... other config properties
addons: [
// ... other addons
"storybook-addon-mantine",
],
};

export default config;
```

### Themes

```ts
// src/themes.ts
import { createTheme } from "@mantine/core";

export const greenTheme = createTheme({
primaryColor: "green",
// ... other theme override properties
});

export const brandTheme = createTheme({
fontFamily: "serif",
// ... other theme override properties
});
```

### Pass your theme(s) to the addon

Do this in your `.storybook/preview.tsx` file:

```ts
import "@mantine/core/styles.css";

import { withMantineThemes } from "storybook-addon-mantine";
import { greenTheme, brandTheme } from "../themes";

export const decorators = [
withMantineThemes({
themes: [
{
id: "brand-theme",
name: "Brand Theme",
...brandTheme,
},
{
id: "light-green",
name: "Light Green Theme",
...greenTheme,
},
],
}),
];
```

## Options

### `withMantineThemes({themes, mantineProviderProps})`

Call this function inside the decorators array in `.storybook/preview.js`.

### `themes`

List of themes to show inside Storybook.
Each theme should be a valid [Mantine Theme Override Object](https://mantine.dev/theming/theme-object/#store-theme-override-object-in-a-variable).

Additionally, each theme object must have:

- `id: string` - required, this must be unique between themes
- `name?: string` - optional, name to show in list to pick themes from.

### `mantineProviderProps`

This is an optional object of props to pass to the `MantineProvider` component.
See [Documentation Page](https://mantine.dev/theming/mantine-provider/#mantineprovider-props) for details.

> Most use cases won't need to set anything for this object.
### Color Schemes (Dark/Light Mode) Support

> Cannot use mantine hooks in addons for storybook v7. Need storybook manager UI to be upgraded to react 18 (so addon can use the useId hook from react). Thi seems [scheduled for Storybook 8 release](https://github.com/storybookjs/storybook/milestone/89).
Workaround is to configure mantine `useMantineColorScheme` hook in your storybook instance, see [Mantine documentation for all steps](https://mantine.dev/guides/storybook/).

Install Storybook addons:

```shell
npm install -D storybook-dark-mode @storybook/addon-styling storybook-addon-mantine
```

Add addons to .storybook/main.ts:

```jsx
import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
// ... other config properties
addons: [
// ... other addons
"@storybook/addon-styling",
"storybook-dark-mode",
"storybook-addon-mantine",
],
};

export default config;
```

Create your theme(s) as explained previously.

```jsx
// Import styles of packages that you've installed.
// All packages except `@mantine/hooks` require styles imports
import "@mantine/core/styles.css";

import React, { useEffect } from "react";
import { addons } from "@storybook/preview-api";
import { DARK_MODE_EVENT_NAME } from "storybook-dark-mode";
import { MantineProvider, useMantineColorScheme } from "@mantine/core";
import { withMantineThemes } from "storybook-addon-mantine";
import { greenTheme, brandTheme } from "../themes";

const channel = addons.getChannel();

function ColorSchemeWrapper({ children }: { children: React.ReactNode }) {
const { setColorScheme } = useMantineColorScheme();
const handleColorScheme = (value: boolean) =>
setColorScheme(value ? "dark" : "light");

useEffect(() => {
channel.on(DARK_MODE_EVENT_NAME, handleColorScheme);
return () => channel.off(DARK_MODE_EVENT_NAME, handleColorScheme);
}, [channel]);

return <>{children}</>;
}

export const decorators = [
(renderStory: any) => (
<ColorSchemeWrapper>{renderStory()}</ColorSchemeWrapper>
),
withMantineThemes({
themes: [
{
id: "brand-theme",
name: "Brand Theme",
...brandTheme,
},
{
id: "light-green",
name: "Light Green Theme",
...greenTheme,
},
],
}),
];
```

That should be it!

`npm run storybook`

## Versions

### 3.0

Support [Mantine v7 Release](https://v7.mantine.dev/guides/6x-to-7x).

These are notable

- [React 18+ Only](https://mantine.dev/changelog/7-0-0/#react-18-only)
- [Color scheme not in theme object](https://mantine.dev/changelog/7-0-0/#built-in-color-scheme-manager)
- [Create theme function](<https://mantine.dev/changelog/7-0-0/#createtheme-function>
- [Theme object changes](https://mantine.dev/changelog/7-0-0/#theme-object-changes)

### 2.0

- Support for Storybook 7 - will not work with older versions of Storybook.
- Rebuilt entire package using [AddonKit](https://github.com/storybookjs/addon-kit) and Typescript.
- Keeps selected theme consistently when switching between component examples, rather than defaulting back to first theme every time.

### 1.3

- Support Mantine v6 (<https://mantine.dev/changelog/6-0-0/>).
- Only Require `@mantine/core` as peer dependency

### 1.2

- Update peer dependencies

### 1.1

- Support Mantine v5 (<https://mantine.dev/changelog/5-0-0/>).
- Adds second parameter `mantineProviderProps` to `mantineTheme(themesList, mantineProviderProps)`

### 1.0

Initial release
Loading

0 comments on commit 17bbad4

Please sign in to comment.