diff --git a/.gitignore b/.gitignore index 9919494..7c15ae9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ node_modules # build -dist \ No newline at end of file +dist +*storybook.log \ No newline at end of file diff --git a/.storybook/main.ts b/.storybook/main.ts new file mode 100644 index 0000000..4786841 --- /dev/null +++ b/.storybook/main.ts @@ -0,0 +1,20 @@ +import type { StorybookConfig } from '@storybook/react-vite'; + +const config: StorybookConfig = { + stories: [ + '../stories/**/*.mdx', + '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)', + ], + addons: [ + '@storybook/addon-onboarding', + '@storybook/addon-links', + '@storybook/addon-essentials', + '@chromatic-com/storybook', + '@storybook/addon-interactions', + ], + framework: { + name: '@storybook/react-vite', + options: {}, + }, +}; +export default config; diff --git a/.storybook/preview.ts b/.storybook/preview.ts new file mode 100644 index 0000000..adcda96 --- /dev/null +++ b/.storybook/preview.ts @@ -0,0 +1,14 @@ +import type { Preview } from '@storybook/react'; + +const preview: Preview = { + parameters: { + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/i, + }, + }, + }, +}; + +export default preview; diff --git a/bun.lockb b/bun.lockb index 34a6b93..d07d715 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index a1dacce..c41e571 100644 --- a/package.json +++ b/package.json @@ -1,30 +1,23 @@ { "name": "split-text-react", "version": "0.0.0", - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "scripts": { - "build": "tsup", - "test": "jest", - "prettier:check": "prettier --check ./*", - "prettier:format": "prettier --write ./*" - }, + "author": "Julio Salas", "repository": { "type": "git", "url": "git+https://github.com/julio-salas03/split-text-react.git" }, - "author": "Julio Salas", - "license": "MIT", - "bugs": { - "url": "https://github.com/julio-salas03/split-text-react/issues" - }, - "homepage": "https://github.com/julio-salas03/split-text-react#readme", - "description": "", - "peerDependencies": { - "react": ">=16" - }, + "main": "./dist/index.js", + "module": "./dist/index.mjs", "devDependencies": { + "@chromatic-com/storybook": "^1.8.0", + "@storybook/addon-essentials": "^8.2.9", + "@storybook/addon-interactions": "^8.2.9", + "@storybook/addon-links": "^8.2.9", + "@storybook/addon-onboarding": "^8.2.9", + "@storybook/blocks": "^8.2.9", + "@storybook/react": "^8.2.9", + "@storybook/react-vite": "^8.2.9", + "@storybook/test": "^8.2.9", "@swc/core": "^1.7.22", "@swc/jest": "^0.2.36", "@testing-library/dom": "^10.4.0", @@ -33,13 +26,34 @@ "@types/node": "^22.5.0", "@types/react": "^18.3.4", "@types/react-dom": "^18.3.0", + "@types/react-resizable": "^3.0.8", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", "prettier": "^3.3.3", "react": "^18.3.1", "react-dom": "^18.3.1", + "react-resizable": "^3.0.5", "resize-observer-polyfill": "^1.5.1", + "storybook": "^8.2.9", "tsup": "^8.2.4", "typescript": "^5.5.4" - } + }, + "peerDependencies": { + "react": ">=16" + }, + "bugs": { + "url": "https://github.com/julio-salas03/split-text-react/issues" + }, + "description": "", + "homepage": "https://github.com/julio-salas03/split-text-react#readme", + "license": "MIT", + "scripts": { + "build": "tsup", + "test": "jest", + "prettier:check": "prettier --check ./*", + "prettier:format": "prettier --write ./*", + "storybook": "storybook dev -p 6006", + "build-storybook": "storybook build" + }, + "types": "./dist/index.d.ts" } diff --git a/stories/SplitText.stories.tsx b/stories/SplitText.stories.tsx new file mode 100644 index 0000000..db3fc1c --- /dev/null +++ b/stories/SplitText.stories.tsx @@ -0,0 +1,46 @@ +import React from 'react'; +import type { Meta, StoryObj } from '@storybook/react'; +import { SplitText, SplitTextProps } from './../src/index'; +import { Resizable } from 'react-resizable/'; +import 'react-resizable/css/styles.css'; + +const meta: Meta = { + component: SplitText, +}; + +export default meta; + +type Story = StoryObj; + +const Component = ({ children, ...rest }: SplitTextProps) => { + const [size, setSize] = React.useState({ width: 300, height: 400 }); + return ( + <> + setSize(size)} + > +
+ {children} +
+
+ + ); +}; + +export const Primary: Story = { + args: { + children: + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ac urna hendrerit, aliquet quam eget, faucibus lectus.', + }, + render: props => , +}; diff --git a/tests/index.test.tsx b/tests/index.test.tsx index 82c90f9..9aee6a8 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -16,14 +16,14 @@ describe('SplitText', () => { expect(() => render( -
foo
+
Lorem ipsum
) ).toThrow(); }); it('should support computed text', () => { - expect(() => render(foo {5})).not.toThrow(); + expect(() => render(Lorem {'ipsum'})).not.toThrow(); }); it('should forward the ref to the component', () => { @@ -37,7 +37,7 @@ describe('SplitText', () => { expect(ref.current).toBeInstanceOf(HTMLElement); }; - return Hello World; + return Lorem ipsum; }; render();