Skip to content

Upgrade Storybook to v7 #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a824c11
🎉 Upgrade to Storybook v7 & introduce ability to use Vite & TS
rushi Nov 1, 2023
c4bc9da
Remove wrong export
rushi Nov 1, 2023
49b541a
Add tailwindMerge & 'cn'
rushi Nov 1, 2023
0a6d9ff
Restore ES Lint
rushi Nov 1, 2023
a1cc1f9
Fix build
rushi Nov 2, 2023
77677ff
Exclude stories from lint
rushi Nov 6, 2023
75f29cd
Merge branch 'xola:master' into sb-7
rushi Nov 13, 2023
59b397f
Merge branch 'master' of github.com:xola/ui-kit into sb-7
rushi Nov 13, 2023
9b91f78
Convert stories to CSF-3
rushi Nov 13, 2023
5504c48
Re-use `size` params since we always have the same size
rushi Nov 13, 2023
f2ef0e3
Add .xo-config
rushi Nov 13, 2023
3a1f46a
Update lint:report script
rushi Nov 13, 2023
44b8e52
Set tags: ["autodocs"] to generate Docs page
rushi Nov 13, 2023
2c11c4c
Cleanup and update config
rushi Nov 13, 2023
6296a7c
Copy tailwind and postcss config into output folder
rushi Nov 13, 2023
1f0f65f
Remove .mjs file
rushi Nov 13, 2023
dcad056
Rename vars for stories to be clearer
rushi Nov 13, 2023
829edeb
Remove changes for Docs
rushi Nov 13, 2023
77d2b29
Rename helpers
rushi Nov 13, 2023
3436105
Add pseudo-states and figma plugin
rushi Nov 13, 2023
eac966b
Trim down stories
rushi Nov 13, 2023
ea5de23
Add docs
rushi Nov 13, 2023
4560a9c
Implement "play" function & trim story code
rushi Nov 13, 2023
112cf6c
Update changes from master
rushi Jan 8, 2024
2fbf4fc
Merge branch 'master' of github.com:xola/ui-kit into sb-7
rushi Jan 8, 2024
7a56416
Upgrade Storybook to 7.6 and use ES Modules
rushi Jan 8, 2024
6acff89
Merge branch 'master' into sb-7
rushi Jan 21, 2024
40b51b0
🧹 Lint
rushi Jan 21, 2024
d3cefe0
Fix build file
rushi Jan 21, 2024
e899f2e
postcss mjs file
rushi Jan 21, 2024
6a7f195
Update build
rushi Jan 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
src/theme.js
dist
build
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
src/theme.js
build
dist
package-lock.json
node_modules
.github
storybook-static
git_ignore
18 changes: 0 additions & 18 deletions .storybook/main.js

This file was deleted.

25 changes: 25 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
core: {
disableTelemetry: true,
},
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"storybook-addon-pseudo-states",
"@storybook/addon-interactions",
"@storybook/addon-mdx-gfm",
],
framework: {
name: "@storybook/react-vite",
options: {},
},
docs: {
autodocs: "tag",
defaultName: "Docs",
},
staticDirs: ["../public"],
};
export default config;
2 changes: 1 addition & 1 deletion .storybook/manager.js → .storybook/manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addons } from "@storybook/addons";
import { addons } from "@storybook/manager-api";
import xola from "./xola";

addons.setConfig({
Expand Down
5 changes: 0 additions & 5 deletions .storybook/preview-head.html

This file was deleted.

26 changes: 0 additions & 26 deletions .storybook/preview.js

This file was deleted.

38 changes: 38 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Preview } from "@storybook/react";

import "../index.css";
import xola from "./xola";

const preview: Preview = {
// argTypes: {
// // 👇 All stories expect a className arg
// className: {
// control: "text",
// description: "Tailwind class names to override styling",
// },
// },
parameters: {
docs: {
toc: true,
theme: xola,
},
actions: { argTypesRegex: "^on.*" },
controls: {
matchers: {
text: /^className$/i,
bool: /isLoading|disabled|^should|^is/i,
},
},
options: {
storySort: {
method: "alphabetical",
order: ["Introduction", "Components"],
includeName: true,
},
},
},
};

export default preview;

// https://storybook.js.org/docs/react/writing-stories/naming-components-and-hierarchy#sorting-stories
20 changes: 20 additions & 0 deletions .xo-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"ignorePatterns": ["**/*.test.js*", "**/*.test.ts*", "**/test/**/*.*"],
"rules": {
"unicorn/prevent-abbreviations": [
"error",
{
"replacements": {
"param": false,
"params": false,
"props": false,
"e": false,
"ref": false,
"def": false,
"pkg": false,
"args": false
}
}
]
}
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ $ npm start
```

## Advanced

### Integrate your app with a locally installed UI Kit

In order for this to work you will have to set up an NPM workspace. That means, `ui-kit` and `your-project` has to be in the same directory.
Expand Down Expand Up @@ -151,14 +152,15 @@ Install [np](https://github.com/sindresorhus/np#readme) which will help you publ
npm -g install np
```

Once you're ready, run this command to publish your package
Once you're ready, run this command to publish your package

```bash
npm run build
np <your-new-version> --tag=latest --yolo
```

Then make sure to push all the tags upstream to `xola/ui-kit` repo:

```
git push <upstream-remote> master --tags
```
166 changes: 166 additions & 0 deletions README.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
## Xola UI Kit

Xola's React component library with Tailwind CSS for the next generation of Xola apps. See a preview at https://ui.xola.io

### Requirements

- Node.js v16
- NPM v7 or higher

### Usage

Install the UI kit:

```bash
npm install @xola/ui-kit
```

Install peer dependencies:

```bash
npm install autoprefixer postcss tailwindcss lodash
```

Create PostCSS and Tailwind config files:

```bash
echo 'module.exports = require("@xola/ui-kit/tailwind.config");' > tailwind.config.js
echo 'module.exports = require("@xola/ui-kit/postcss.config");' > postcss.config.js
```

Import main CSS files in your project:

```js
import "@xola/ui-kit/index.css";
import "@xola/ui-kit/build/style.css";
```

UI kit expects you already have a working React dev environment with PostCSS support.

Import and use the components:

```js
import { Button } from "@xola/ui-kit";
```

## Development

### Installation

Install all required dependencies:

```bash
$ nvm use # Project needs Node.js v16 with NPM v7
$ npm install
```

Start the Storybook development server:

```bash
$ npm start
```

## Advanced

### Integrate your app with a locally installed UI Kit

In order for this to work you will have to set up an NPM workspace. That means, `ui-kit` and `your-project` has to be in the same directory.

Start by creating a `package.json` file in your "workspace" directory with the following content:

```json
{
"workspaces": ["ui-kit", "your-project"]
}
```

Your workspace directory should also contain `.npmrc` and `.nvmrc` files. Copy them from this project:

```bash
$ cd workspace
$ cp ui-kit/.npmrc .
$ cp ui-kit/.nvmrc .
```

Now we're ready to install the dependencies for both projects:

```bash
$ cd workspace
$ npm install
```

If all went well, NPM will use locally installed `ui-kit` in `your-project`.

Next, start the build command from `ui-kit`:

```bash
$ cd ui-kit
$ npm run build -- --watch
```

This will build and watch for changes the `ui-kit` project. Any change made in the `ui-kit` should be visible in `your-project`.

If you don't see any changes in your project, that probably means that NPM installed a separate package in your `your-project/node_modules` directory. To fix this, just remove the whole package with the following command:

```bash
$ cd your-project
$ rm -rf node_modules/@xola
```

### Troubleshooting

If you encounter some package related issues, try removing the following directories and running the install command again:

```bash
$ cd workspace
$ rm -rf package-lock.json node_modules ui-kit/node_modules your-project/node_modules
$ npm install
```

### Lint & Auto-fix

To automatically fix lint issues in this project you have the following commands:

```bash
npm run lint # Run lint on `src` and output issues
npm run lint:fix # Run lint and automatically fix any issues. Any that are not fixed are output to screen.
```

## Notes

To avoid issues with how npm v7 resolves peer dependencies, we enabled `legacy-peer-deps` rule in `.npmrc`.

In order to avoid issues in your projects that are using this UI Kit, use the same `.npmrc` file or always run installs with `--legacy-peer-deps` flag.

For example:

```bash
$ npm install --legacy-peer-deps
```

Or:

```bash
$ npm install some-package --legacy-peer-deps
```

## Publishing the Package

Install [np](https://github.com/sindresorhus/np#readme) which will help you publish the package

```bash
npm -g install np
```

Once you're ready, run this command to publish your package

```bash
npm run build
np <your-new-version> --tag=latest --yolo
```

Then make sure to push all the tags upstream to `xola/ui-kit` repo:

```
git push <upstream-remote> master --tags
```
3 changes: 0 additions & 3 deletions babel.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion index.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@layer base {
html {
/* Never change this default! */
@apply text-black text-base;
@apply text-base text-black;
}

a {
Expand Down
Loading