Skip to content

Commit

Permalink
Update Storybook to v7 to fix build error with type module
Browse files Browse the repository at this point in the history
  • Loading branch information
melanieseltzer committed Oct 13, 2022
1 parent 1c71006 commit 74ad351
Show file tree
Hide file tree
Showing 12 changed files with 2,209 additions and 3,753 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
extends: ['plugin:mdx/recommended'],
},
{
files: ['docs/**/*'],
files: ['stories/**/*'],
rules: {
'react/display-name': 'off',
'react/prop-types': 'off',
Expand Down
16 changes: 0 additions & 16 deletions .storybook/main.js

This file was deleted.

19 changes: 19 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
stories: ['../docs/**/*.mdx', '../stories/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
{
name: '@storybook/addon-docs',
options: {
transcludeMarkdown: true,
},
},
],
framework: {
name: '@storybook/react-vite',
options: {},
},
core: {},
docs: {
docsPage: false,
},
};
7 changes: 0 additions & 7 deletions .storybook/manager.js

This file was deleted.

2 changes: 1 addition & 1 deletion .storybook/preview-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
margin: 0 auto !important;
}

#docs-root p {
#storybook-docs p {
font-size: 1rem !important;
}

Expand Down
File renamed without changes.
43 changes: 0 additions & 43 deletions docs/demoWithoutHook.stories.tsx

This file was deleted.

File renamed without changes.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
"format": "yarn format:fix && yarn lint:fix",
"prepare": "husky install",
"typecheck": "tsc --noEmit",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"changeset": "changeset",
"release": "yarn build && changeset publish"
},
Expand All @@ -68,10 +68,9 @@
"@mels/eslint-config-react": "^1.0.0",
"@mels/eslint-config-typescript": "^1.0.1",
"@mels/prettier-config": "^1.0.0",
"@storybook/addon-docs": "^6.5.12",
"@storybook/builder-webpack5": "^6.5.12",
"@storybook/manager-webpack5": "^6.5.12",
"@storybook/react": "^6.5.12",
"@storybook/addon-docs": "7.0.0-alpha.34",
"@storybook/react": "7.0.0-alpha.34",
"@storybook/react-vite": "^7.0.0-alpha.34",
"@testing-library/react": "^13.4.0",
"@types/jest": "^29.1.1",
"@types/react": "^18.0.21",
Expand All @@ -87,6 +86,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rimraf": "^3.0.2",
"storybook": "7.0.0-alpha.34",
"ts-jest": "^29.0.3",
"typescript": "^4.8.4"
}
Expand Down
File renamed without changes.
46 changes: 32 additions & 14 deletions docs/demoWithHook.stories.tsx → stories/hook.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,48 @@
import * as React from 'react';
import { Meta, Story } from '@storybook/react';
import type { StoryFn } from '@storybook/react';
import { Meta } from '@storybook/react';

import { useCaretPosition } from '../src';

import { DemoInput } from './DemoInput';

const meta: Meta = {
title: 'Hook Demo',
parameters: {
previewTabs: {
'storybook/docs/panel': { hidden: true },
},
},
};
export default {
title: 'useCaretPosition',
} as Meta;

export const TheProblemItSolves: StoryFn = () => {
const [text, setText] = React.useState('hello world');

return (
<div>
<p>
This input has a side effect in its <code>onChange</code> handler.
</p>

<p>
React loses caret position after each keystroke and jumps the caret to
the end of the input, making for a terrible typing experience 👎
</p>

export default meta;
<p>Type anywhere in the middle of the input to simulate this behavior.</p>

export const HookDemo: Story = () => {
<DemoInput
value={text}
onChange={(value: string) => {
setText(value);
}}
/>
</div>
);
};

export const Demo: StoryFn = () => {
const { start, end, ref, updateCaret } = useCaretPosition();

const [text, setText] = React.useState('hello world');

return (
<div>
<h1>useCaretPosition</h1>

<p>
When using the hook to track the caret position, the caret will not get
booted to the end of the input on each keystroke 🎉
Expand All @@ -43,7 +61,7 @@ export const HookDemo: Story = () => {
}}
/>

<div>
<div style={{ marginTop: '1rem' }}>
start position: <strong>{start}</strong>, end position:{' '}
<strong>{end}</strong>
</div>
Expand Down
Loading

0 comments on commit 74ad351

Please sign in to comment.