Skip to content

Storybook #2

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

Merged
merged 6 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"extends": ["next", "next/core-web-vitals", "prettier"],
"extends": ["next", "next/core-web-vitals", "prettier", "plugin:storybook/recommended"],
"plugins": ["simple-import-sort"],
"rules": {
"simple-import-sort/imports": "warn",
"@next/next/no-img-element": "off"
"@next/next/no-img-element": "off",
"@next/next/no-html-link-for-pages": "off"
}
}
1 change: 1 addition & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: CI

on:
pull_request:
push:
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/deploy-storybook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Workflow name
name: Build and Publish Storybook to GitHub Pages

on:
push:
branches:
- 'main'

permissions:
contents: read
pages: write
id-token: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- uses: bitovi/[email protected]
with:
install_command: npm i
build_command: npm run storybook:build
path: dist/storybook
2 changes: 2 additions & 0 deletions .github/workflows/publish-to-npm.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: Publish Package to NPM

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ stats.html

**/.eslintcache
.vercel

*storybook.log
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npm run pre-commit
lint-staged
6 changes: 1 addition & 5 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
**/.eslintrc.js
**/*.md
**/package.json
**/tsconfig.json
pnpm-workspace.yaml
pnpm-lock.yaml
turbo.json
package-lock.json
19 changes: 19 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { StorybookConfig } from '@storybook/nextjs';

const config: StorybookConfig = {
"stories": [
"../src/**/*.mdx",
"../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"
],
"addons": [
"@storybook/addon-essentials",
"@storybook/addon-onboarding",
"@chromatic-com/storybook",
"@storybook/addon-interactions"
],
"framework": {
"name": "@storybook/nextjs",
"options": {}
}
};
export default config;
6 changes: 6 additions & 0 deletions .storybook/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { addons } from '@storybook/manager-api';
import { theme } from './theme';

addons.setConfig({
theme,
});
8 changes: 8 additions & 0 deletions .storybook/near-ai-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from 'react';
import type { Preview } from '@storybook/react';
import { NearAiUiProvider } from '../src';
import { theme } from './theme';
import './styles.scss';

const useRouter = () => {
return {
prefetch: () => {},
replace: () => {},
push: () => {},
};
};

const preview: Preview = {
globalTypes: {
theme: {
description: 'Global theme for components',
toolbar: {
title: 'Theme',
items: [
{
value: 'dark',
title: 'Dark',
icon: 'moon',
},
{
value: 'light',
title: 'Light',
icon: 'sun',
},
],
dynamicTitle: true,
},
},
},

initialGlobals: {
theme: 'dark',
},

parameters: {
backgrounds: {
disable: true,
},
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
docs: {
theme,
},
},
decorators: [
(Story, context) => (
<NearAiUiProvider
value={{
forcedTheme: context.globals.theme,
Link: (props) => <a {...props} />,
useRouter: useRouter,
}}
>
{/* 👇 Decorators in Storybook also accept a function. Replace <Story/> with Story() to enable it */}
<Story />
</NearAiUiProvider>
),
],
};

export default preview;
3 changes: 3 additions & 0 deletions .storybook/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.sbdocs-preview {
background: var(--sand-1) !important;
}
10 changes: 10 additions & 0 deletions .storybook/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { create } from '@storybook/theming';

// @ts-expect-error
import NearAiLogo from './near-ai-logo.svg';

export const theme = create({
base: 'dark',
brandTitle: 'NEAR AI UI | Storybook',
brandImage: NearAiLogo,
});
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,14 @@ export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en" suppressHydrationWarning>
<head>
<meta
name="viewport"
content="width=device-width, initial-scale=1, minimum-scale=1"
/>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
</head>

<body>
<NearAiUiProvider
value={{
Link,
useRouter
useRouter,
}}
>
<Toaster />
Expand Down Expand Up @@ -81,6 +78,14 @@ npm run test:watch
- Test your local changes
- Push a PR for review

## Storybook

Boot up local [Storybook](https://storybook.js.org) server and watch for changes:

```
npm run storybook
```

## Test Local Changes

Follow these steps to preview local changes to the UI library within any project that depends on the library:
Expand Down
Loading