├── .eslintignore ├── .eslintrc ├── .gitattributes ├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── pull_request.yaml │ ├── push.yaml │ └── release.yaml ├── .gitignore ├── .prettierignore ├── .prettierrc ├── .storybook ├── main.ts ├── manager.ts └── preview.tsx ├── CHANGELOG.md ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── src ├── @types │ └── styled-components │ │ └── index.d.ts ├── components │ ├── Alert │ │ ├── Alert.stories.tsx │ │ ├── Alert.tsx │ │ └── index.ts │ ├── Avatar │ │ ├── Avatar.stories.tsx │ │ ├── Avatar.tsx │ │ ├── AvatarGroup.stories.tsx │ │ ├── AvatarGroup.tsx │ │ └── index.ts │ ├── Badge │ │ ├── Badge.stories.tsx │ │ ├── Badge.tsx │ │ └── index.ts │ ├── Box │ │ ├── Box.stories.tsx │ │ ├── Box.tsx │ │ └── index.ts │ ├── Button │ │ ├── Button.stories.tsx │ │ ├── Button.tsx │ │ ├── IconButton.stories.tsx │ │ ├── IconButton.tsx │ │ └── index.ts │ ├── Checkbox │ │ ├── Checkbox.stories.tsx │ │ ├── Checkbox.tsx │ │ └── index.ts │ ├── CloseButton │ │ ├── CloseButton.stories.tsx │ │ ├── CloseButton.tsx │ │ └── index.ts │ ├── Code │ │ ├── Code.stories.tsx │ │ ├── Code.tsx │ │ └── index.ts │ ├── Container │ │ ├── Container.stories.tsx │ │ ├── Container.tsx │ │ └── index.ts │ ├── Divider │ │ ├── Divider.stories.tsx │ │ ├── Divider.tsx │ │ └── index.ts │ ├── Drawer │ │ ├── Drawer.stories.tsx │ │ ├── Drawer.tsx │ │ └── index.ts │ ├── Flex │ │ ├── Flex.stories.tsx │ │ ├── Flex.tsx │ │ └── index.ts │ ├── Grid │ │ ├── Grid.stories.tsx │ │ ├── Grid.tsx │ │ └── index.ts │ ├── Heading │ │ ├── Heading.stories.tsx │ │ ├── Heading.tsx │ │ └── index.ts │ ├── Image │ │ ├── Image.stories.tsx │ │ ├── Image.tsx │ │ └── index.ts │ ├── Input │ │ ├── Input.stories.tsx │ │ ├── Input.tsx │ │ └── index.ts │ ├── Kbd │ │ ├── Kbd.stories.tsx │ │ ├── Kbd.tsx │ │ └── index.ts │ ├── Link │ │ ├── Link.stories.tsx │ │ ├── Link.tsx │ │ └── index.ts │ ├── Menu │ │ ├── Menu.stories.tsx │ │ ├── Menu.tsx │ │ ├── MenuDivider.tsx │ │ ├── MenuHeader.tsx │ │ ├── MenuItem.tsx │ │ └── index.ts │ ├── Modal │ │ ├── Modal.stories.tsx │ │ ├── Modal.tsx │ │ ├── ModalBody.tsx │ │ ├── ModalCloseButton.tsx │ │ ├── ModalFooter.tsx │ │ ├── ModalHeader.tsx │ │ └── index.ts │ ├── Overlay │ │ ├── Overlay.stories.tsx │ │ ├── Overlay.tsx │ │ └── index.ts │ ├── Portal │ │ ├── Portal.stories.tsx │ │ ├── Portal.tsx │ │ └── index.ts │ ├── Progress │ │ ├── Circular.tsx │ │ ├── Horizontal.tsx │ │ ├── Progress.stories.tsx │ │ ├── Progress.tsx │ │ ├── index.ts │ │ └── styled.tsx │ ├── Radio │ │ ├── Radio.stories.tsx │ │ ├── Radio.tsx │ │ └── index.ts │ ├── Select │ │ ├── Select.stories.tsx │ │ ├── Select.tsx │ │ ├── index.ts │ │ └── util.ts │ ├── Skeleton │ │ ├── Skeleton.stories.tsx │ │ ├── Skeleton.tsx │ │ └── index.ts │ ├── Spinner │ │ ├── Spinner.stories.tsx │ │ ├── Spinner.tsx │ │ └── index.ts │ ├── Stack │ │ ├── Stack.stories.tsx │ │ ├── Stack.tsx │ │ └── index.ts │ ├── Switch │ │ ├── Switch.stories.tsx │ │ ├── Switch.tsx │ │ └── index.ts │ ├── Tabs │ │ ├── Tab.tsx │ │ ├── Tabs.stories.tsx │ │ ├── Tabs.tsx │ │ └── index.tsx │ ├── Tag │ │ ├── Tag.stories.tsx │ │ ├── Tag.tsx │ │ ├── TagAction.tsx │ │ ├── TagIcon.tsx │ │ ├── TagLabel.tsx │ │ └── index.ts │ ├── Text │ │ ├── Text.stories.tsx │ │ ├── Text.tsx │ │ └── index.ts │ ├── TextArea │ │ ├── TextArea.stories.tsx │ │ ├── TextArea.tsx │ │ └── index.ts │ ├── Theme │ │ ├── ThemeProvider.stories.tsx │ │ ├── ThemeProvider.tsx │ │ ├── index.ts │ │ └── injectGlobalStyles.tsx │ ├── Toast │ │ ├── ToastProvider.stories.tsx │ │ ├── ToastProvider.tsx │ │ ├── index.ts │ │ └── util.ts │ ├── Tooltip │ │ ├── Tooltip.stories.tsx │ │ ├── Tooltip.tsx │ │ └── index.ts │ └── index.ts ├── hooks │ ├── index.ts │ ├── useDisclosure.ts │ ├── useImage.ts │ ├── useKeyPress.ts │ └── usePopper.ts ├── index.ts ├── system │ ├── componentStyles.ts │ ├── index.ts │ ├── sxMixin.ts │ └── system.ts ├── theme │ ├── components │ │ ├── Alert.ts │ │ ├── Avatar.ts │ │ ├── Badge.ts │ │ ├── Button.ts │ │ ├── Checkbox.ts │ │ ├── CloseButton.ts │ │ ├── Code.ts │ │ ├── Container.ts │ │ ├── Divider.ts │ │ ├── Drawer.ts │ │ ├── Heading.ts │ │ ├── Image.ts │ │ ├── Input.ts │ │ ├── Kbd.ts │ │ ├── Link.ts │ │ ├── Menu.ts │ │ ├── Modal.tsx │ │ ├── Overlay.ts │ │ ├── Progress.ts │ │ ├── Radio.ts │ │ ├── Skeleton.ts │ │ ├── Spinner.ts │ │ ├── Switch.ts │ │ ├── Tabs.ts │ │ ├── Tag.ts │ │ ├── Text.ts │ │ ├── TextArea.ts │ │ ├── Toast.ts │ │ ├── Tooltip.ts │ │ └── index.ts │ ├── foundations │ │ ├── animation.ts │ │ ├── borders.ts │ │ ├── breakpoints.ts │ │ ├── colors.ts │ │ ├── index.ts │ │ ├── shadows.ts │ │ ├── sizes.ts │ │ ├── transition.ts │ │ ├── typography.ts │ │ └── zIndices.ts │ ├── index.ts │ └── types.ts ├── types.ts └── util │ └── index.ts └── tsconfig.json /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | coverage 4 | storybook-static 5 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "airbnb-typescript", 4 | "airbnb/hooks", 5 | "plugin:@typescript-eslint/recommended", 6 | "plugin:prettier/recommended", 7 | "prettier/react", 8 | "prettier/@typescript-eslint", 9 | "plugin:jest/recommended" 10 | ], 11 | "parserOptions": { 12 | "project": "./tsconfig.json" 13 | }, 14 | "rules": { 15 | "@typescript-eslint/explicit-module-boundary-types": "off", 16 | "@typescript-eslint/naming-convention": "off", 17 | "@typescript-eslint/no-empty-interface": "off", 18 | "@typescript-eslint/no-explicit-any": "off", 19 | "import/no-cycle": "off", 20 | "import/prefer-default-export": "off", 21 | "jsx-a11y/accessible-emoji": "off", 22 | "no-underscore-dangle": "off", 23 | "react/jsx-props-no-spreading": "off" 24 | }, 25 | "overrides": [ 26 | { 27 | "files": ["**/*.tsx"], 28 | "rules": { 29 | "react/prop-types": "off" 30 | } 31 | }, 32 | { 33 | "files": ["**/*.stories.tsx"], 34 | "rules": { 35 | "import/no-extraneous-dependencies": "off" 36 | } 37 | } 38 | ], 39 | "settings": { 40 | "react": { 41 | "version": "detect" 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Common .gitattributes file courtesy of 2 | # https://github.com/alexkaratarakis/gitattributes/blob/master/Common.gitattributes 3 | 4 | # Auto detect text files and perform LF normalization 5 | * text=auto eol=lf 6 | 7 | # The above will handle all files NOT found below 8 | 9 | # Documents 10 | *.pdf diff=astextplain 11 | *.PDF diff=astextplain 12 | *.rtf diff=astextplain 13 | *.RTF diff=astextplain 14 | *.md text 15 | 16 | # Graphics 17 | *.png binary 18 | *.jpg binary 19 | *.jpeg binary 20 | *.gif binary 21 | *.tif binary 22 | *.tiff binary 23 | *.ico binary 24 | # SVG treated as an asset (binary) by default. 25 | *.svg binary 26 | #*.svg text 27 | *.eps binary 28 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | Write a brief description of the changes introduced by this pull request. 4 | 5 | ### Related Issues 6 | 7 | Link to the issue that is fixed by this PR (if there is one) 8 | e.g. Fixes #1234, Addresses #1234, Related to #1234, etc. 9 | -------------------------------------------------------------------------------- /.github/workflows/pull_request.yaml: -------------------------------------------------------------------------------- 1 | name: Pull Request CI 2 | 3 | on: 4 | pull_request: 5 | types: 6 | - opened 7 | - synchronize 8 | 9 | jobs: 10 | deploy-draft-on-any-pull-request: 11 | name: Deploy draft to Netlify 12 | runs-on: ubuntu-latest 13 | if: github.event_name == 'pull_request' && github.ref != 'refs/heads/master' 14 | steps: 15 | - name: Checkout repository 16 | uses: actions/checkout@v2 17 | 18 | - name: Install dependencies 19 | run: npm ci 20 | 21 | - name: Build Storybook 22 | run: npm run build:storybook 23 | 24 | - name: Deploy draft to Netlify 25 | uses: South-Paw/action-netlify-deploy@v1.2.0 26 | with: 27 | github-token: ${{ secrets.GITHUB_TOKEN }} 28 | netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }} 29 | netlify-site-id: ${{ secrets.NETLIFY_SITE_ID }} 30 | build-dir: "./storybook-static" 31 | github-deployment-environment: development 32 | draft: true 33 | -------------------------------------------------------------------------------- /.github/workflows/push.yaml: -------------------------------------------------------------------------------- 1 | name: Push CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | lint: 7 | name: Lint 8 | runs-on: ubuntu-latest 9 | if: github.event_name == 'push' 10 | steps: 11 | - name: Checkout repository 12 | uses: actions/checkout@v2 13 | 14 | - name: Install dependencies 15 | run: npm ci 16 | 17 | - name: Lint 18 | run: npm run lint 19 | 20 | test: 21 | name: Test 22 | runs-on: ubuntu-latest 23 | if: github.event_name == 'push' 24 | steps: 25 | - name: Checkout repository 26 | uses: actions/checkout@v2 27 | 28 | - name: Install dependencies 29 | run: npm ci 30 | 31 | - name: Test 32 | run: npm run test 33 | env: 34 | CI: true 35 | 36 | build: 37 | name: Build 38 | runs-on: ubuntu-latest 39 | if: github.event_name == 'push' 40 | steps: 41 | - name: Checkout repository 42 | uses: actions/checkout@v2 43 | 44 | - name: Install dependencies 45 | run: npm ci 46 | 47 | - name: Build Package 48 | run: npm run build 49 | 50 | deploy-draft-on-master-commit: 51 | name: Deploy draft to Netlify 52 | runs-on: ubuntu-latest 53 | if: github.event_name == 'push' && github.ref == 'refs/heads/master' 54 | steps: 55 | - name: Checkout repository 56 | uses: actions/checkout@v2 57 | 58 | - name: Install dependencies 59 | run: npm ci 60 | 61 | - name: Build Storybook 62 | run: npm run build:storybook 63 | 64 | - name: Deploy draft build to Netlify 65 | uses: South-Paw/action-netlify-deploy@v1.2.0 66 | with: 67 | github-token: ${{ secrets.GITHUB_TOKEN }} 68 | netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }} 69 | netlify-site-id: ${{ secrets.NETLIFY_SITE_ID }} 70 | build-dir: "./storybook-static" 71 | github-deployment-environment: development 72 | draft: true 73 | comment-on-commit: true 74 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: Release CI 2 | 3 | on: 4 | release: 5 | types: 6 | - created 7 | 8 | jobs: 9 | deploy-production-on-master-release: 10 | name: Publish release to Netlify 11 | runs-on: ubuntu-latest 12 | if: github.event_name == 'release' && github.event.action == 'created' 13 | steps: 14 | - name: Checkout repository 15 | uses: actions/checkout@v2 16 | 17 | - name: Install dependencies 18 | run: npm ci 19 | 20 | - name: Build Storybook 21 | run: npm run build:storybook 22 | 23 | - name: Deploy production to Netlify 24 | uses: South-Paw/action-netlify-deploy@v1.2.0 25 | with: 26 | github-token: ${{ secrets.GITHUB_TOKEN }} 27 | netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }} 28 | netlify-site-id: ${{ secrets.NETLIFY_SITE_ID }} 29 | build-dir: "./storybook-static" 30 | github-deployment-environment: production 31 | comment-on-commit: true 32 | 33 | publish-package: 34 | name: Publish 35 | runs-on: ubuntu-latest 36 | if: github.event_name == 'release' && github.event.action == 'created' 37 | steps: 38 | - name: Checkout repository 39 | uses: actions/checkout@v2 40 | 41 | - name: Install dependencies 42 | run: npm ci 43 | 44 | - name: Build package 45 | run: npm run build 46 | 47 | - name: Publish package 48 | uses: JS-DevTools/npm-publish@v1 49 | with: 50 | token: ${{ secrets.NPM_TOKEN }} 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .DS_Store 3 | node_modules 4 | .cache 5 | coverage 6 | dist 7 | storybook-static 8 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | coverage 4 | storybook-static 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "endOfLine": "lf", 3 | "printWidth": 120, 4 | "singleQuote": true, 5 | "trailingComma": "all" 6 | } 7 | -------------------------------------------------------------------------------- /.storybook/main.ts: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | stories: ['../src/**/*.stories.@(tsx|mdx)'], 3 | addons: ['@storybook/addon-essentials'], 4 | }; 5 | -------------------------------------------------------------------------------- /.storybook/manager.ts: -------------------------------------------------------------------------------- 1 | import { addons } from '@storybook/addons'; 2 | import { create } from '@storybook/theming'; 3 | 4 | addons.setConfig({ 5 | theme: create({ 6 | base: 'light', 7 | brandTitle: '🌶️ Spicy UI', 8 | brandUrl: 'https://github.com/spicy-ui/core', 9 | }), 10 | }); 11 | -------------------------------------------------------------------------------- /.storybook/preview.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { ThemeProvider } from '../src'; 3 | import { Parameters } from '@storybook/react'; 4 | 5 | export const parameters: Parameters = { 6 | controls: { expanded: true }, 7 | layout: 'padded', 8 | options: { storySort: { method: 'alphabetical' } }, 9 | }; 10 | 11 | const withThemeProvider = (Story) => ( 12 | 13 | 14 | 15 | ); 16 | 17 | export const decorators = [withThemeProvider]; 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Alex Gabites 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spicy-ui 2 | 3 | 🌶️ A themable and extensible React UI library, ready to use out of the box 4 | 5 | [![npm](https://img.shields.io/npm/v/@spicy-ui/core.svg)](https://www.npmjs.com/package/@spicy-ui/core) 6 | [![Dependencies](https://david-dm.org/spicy-ui/core/status.svg)](https://david-dm.org/spicy-ui/core) 7 | [![Dev Dependencies](https://david-dm.org/spicy-ui/core/dev-status.svg)](https://david-dm.org/spicy-ui/core?type=dev) 8 | 9 | ## Basic usage 10 | 11 | Install Spicy UI to your React project with `npm i @spicy-ui/core styled-components` 12 | 13 | ```js 14 | import React from 'react'; 15 | import { Button, ThemeProvider } from '@spicy-ui/core'; 16 | 17 | export const App = () => ( 18 | 19 | 20 | 21 | ); 22 | ``` 23 | 24 | See the [documentation](https://spicy-ui.netlify.app/) for components, theming and advanced usage. 25 | 26 | ## Issues and Bugs 27 | 28 | If you happen to find any, please report them [here](https://github.com/spicy-ui/core/issues) so they can be squashed. 29 | 30 | ## Development and Contributing 31 | 32 | Pull the repo and then install dependencies with `npm`. 33 | 34 | In the root directory, use `npm run start:storybook` to run Storybook on `localhost:9000` 35 | 36 | See the `package.json` for other scripts such as `clean`, `test` and `lint`. 37 | 38 | ## License 39 | 40 | MIT, see the [LICENSE](./LICENSE) file. 41 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@spicy-ui/core", 3 | "version": "0.1.0-alpha.9", 4 | "description": "A themable and extensible React UI library, ready to use out of the box", 5 | "keywords": [ 6 | "react", 7 | "react-components", 8 | "ui", 9 | "ui-components", 10 | "components", 11 | "component-library", 12 | "design-system", 13 | "library", 14 | "spicy", 15 | "spicy-ui", 16 | "styled-components" 17 | ], 18 | "homepage": "https://github.com/spicy-ui/core", 19 | "bugs": "https://github.com/spicy-ui/core/issues", 20 | "license": "MIT", 21 | "author": { 22 | "name": "Alex Gabites", 23 | "email": "hello@southpaw.co.nz", 24 | "url": "http://southpaw.co.nz" 25 | }, 26 | "files": [ 27 | "dist" 28 | ], 29 | "main": "dist/index.js", 30 | "typings": "dist/index.d.ts", 31 | "module": "dist/core.esm.js", 32 | "repository": { 33 | "type": "git", 34 | "url": "https://github.com/spicy-ui/core.git" 35 | }, 36 | "scripts": { 37 | "clean": "rimraf dist storybook-static", 38 | "start": "tsdx watch", 39 | "start:storybook": "start-storybook -p 9000", 40 | "build": "tsdx build", 41 | "build:storybook": "build-storybook", 42 | "lint": "eslint ./src && tsc --noEmit", 43 | "test": "tsdx test --passWithNoTests" 44 | }, 45 | "dependencies": { 46 | "@popperjs/core": "^2.9.3", 47 | "@spicy-ui/styled-system": "0.0.1-alpha.3", 48 | "@types/styled-components": "^5.1.12", 49 | "deepmerge": "^4.2.2", 50 | "downshift": "^6.1.7", 51 | "framer-motion": "^4.1.17", 52 | "polished": "^4.1.3", 53 | "react-fast-compare": "^3.2.0", 54 | "react-focus-lock": "^2.5.2", 55 | "react-icons": "^4.2.0", 56 | "react-popper": "^2.2.5", 57 | "styled-normalize": "^8.0.7" 58 | }, 59 | "devDependencies": { 60 | "@storybook/addon-essentials": "^6.3.7", 61 | "@storybook/react": "^6.3.7", 62 | "@types/react": "^17.0.17", 63 | "@types/react-dom": "^17.0.9", 64 | "@types/react-router-dom": "^5.1.8", 65 | "@typescript-eslint/eslint-plugin": "^4.29.1", 66 | "@typescript-eslint/parser": "^4.29.1", 67 | "eslint": "^7.32.0", 68 | "eslint-config-airbnb-typescript": "^12.3.1", 69 | "eslint-plugin-jest": "^24.4.0", 70 | "eslint-plugin-react-hooks": "^4.2.0", 71 | "prettier": "^2.3.2", 72 | "react": "^17.0.2", 73 | "react-dom": "^17.0.2", 74 | "react-json-view": "^1.21.3", 75 | "react-lorem-ipsum": "^1.4.9", 76 | "react-router-dom": "^5.2.0", 77 | "react-uid": "^2.3.1", 78 | "rimraf": "^3.0.2", 79 | "styled-components": "^5.3.0", 80 | "tsdx": "^0.14.1", 81 | "tslib": "^2.3.1", 82 | "typescript": "4.3.5" 83 | }, 84 | "peerDependencies": { 85 | "react": ">=17.0.0", 86 | "react-dom": ">=17.0.0", 87 | "styled-components": ">=5.3.0" 88 | }, 89 | "publishConfig": { 90 | "access": "public" 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/@types/styled-components/index.d.ts: -------------------------------------------------------------------------------- 1 | import 'styled-components'; 2 | import { theme } from '../../theme'; 3 | 4 | type ThemeInterface = typeof theme; 5 | 6 | declare module 'styled-components' { 7 | export interface DefaultTheme extends ThemeInterface {} 8 | } 9 | -------------------------------------------------------------------------------- /src/components/Alert/Alert.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Alert, AlertProps, Box, CloseButton, Link, Stack, Text } from '..'; 4 | import { Button } from '../Button'; 5 | 6 | export default { 7 | title: 'Alert', 8 | component: Alert, 9 | } as Meta; 10 | 11 | export const Usage: Story = (props) => ( 12 | 13 | Hey you! Are you using Spicy UI yet? 14 | 15 | ); 16 | 17 | export const Colors: Story = () => ( 18 | 19 | 20 | Order completed 21 | 22 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque scelerisque molestie leo, eu vestibulum 23 | felis sodales ac. Aliquam nec imperdiet mauris. 24 | 25 | 26 | 27 | 28 | Attention required 29 | 30 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque scelerisque molestie leo, eu vestibulum 31 | felis sodales ac. Aliquam nec imperdiet mauris. 32 | 33 | 34 | 37 | 40 | 41 | 42 | 43 | 44 | There were 2 errors with your submission 45 | 46 | Your password must be at least 8 characters 47 | Your password must include at least 2 special characters 48 | 49 | 50 | 51 | 52 | 53 | Great news! 54 | 55 | A new update is avaliable,{' '} 56 | e.preventDefault()}> 57 | click here 58 | {' '} 59 | to learn more. 60 | 61 | 62 | 63 | 64 | 65 | ); 66 | -------------------------------------------------------------------------------- /src/components/Alert/Alert.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SxProp, useComponentStyles } from '../../system'; 3 | import { ColorScales } from '../../theme'; 4 | import { ChildrenProp, HTMLAttributes, LiteralUnion } from '../../types'; 5 | import { Box } from '../Box'; 6 | 7 | export type AlertColors = ColorScales; 8 | 9 | export interface AlertProps extends HTMLAttributes, ChildrenProp, SxProp { 10 | /** Color of the alert. */ 11 | color?: LiteralUnion; 12 | } 13 | 14 | export const Alert = React.forwardRef((props, ref) => { 15 | const { children, sx, color, ...rest } = props; 16 | 17 | const styles = useComponentStyles('Alert', props); 18 | 19 | return ( 20 | 21 | {children} 22 | 23 | ); 24 | }); 25 | 26 | Alert.defaultProps = { 27 | color: 'gray', 28 | }; 29 | 30 | Alert.displayName = 'Alert'; 31 | -------------------------------------------------------------------------------- /src/components/Alert/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Alert'; 2 | -------------------------------------------------------------------------------- /src/components/Avatar/Avatar.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { HiOutlineGlobe, HiUsers } from 'react-icons/hi'; 4 | import { Avatar, AvatarProps, Box, Stack } from '..'; 5 | 6 | export default { 7 | title: 'Avatar', 8 | component: Avatar, 9 | } as Meta; 10 | 11 | export const Usage: Story = (props) => ; 12 | 13 | export const Sizes: Story = () => ( 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | ); 23 | 24 | export const Variants: Story = () => ( 25 | 26 | 27 | 28 | 29 | 30 | ); 31 | 32 | export const Fallback: Story = () => ( 33 | 34 | 35 | 36 | 37 | 38 | ); 39 | 40 | export const Customizing: Story = () => ( 41 | 42 | } /> 43 | 44 | } 48 | variant="square" 49 | /> 50 | 51 | ); 52 | 53 | export const ChildElements: Story = () => ( 54 | 55 | ping, 68 | }} 69 | /> 70 | 71 | 72 | ); 73 | -------------------------------------------------------------------------------- /src/components/Avatar/Avatar.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { HiOutlineUser } from 'react-icons/hi'; 3 | import { useImage } from '../../hooks'; 4 | import { SxProp, useComponentStyles } from '../../system'; 5 | import { ChildrenProp, HTMLAttributes, LiteralUnion } from '../../types'; 6 | import { Box } from '../Box'; 7 | import { Text } from '../Text'; 8 | 9 | interface AvatarImageProps { 10 | getInitials: (name: string) => string; 11 | icon: React.ReactElement; 12 | name?: string; 13 | src?: string; 14 | } 15 | 16 | const AvatarImage: React.FC = ({ getInitials, icon, name, src }) => { 17 | const { status } = useImage(src); 18 | 19 | if (!src || status !== 'loaded') { 20 | return name ? ( 21 | 22 | {getInitials(name)} 23 | 24 | ) : ( 25 | <>{icon} 26 | ); 27 | } 28 | 29 | return ; 30 | }; 31 | 32 | const defaultGetInitials = (name: string) => { 33 | const [first, last] = name.split(' '); 34 | return first && last ? `${first.charAt(0)}${last.charAt(0)}` : first.charAt(0); 35 | }; 36 | 37 | export type AvatarSizes = '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'; 38 | 39 | export type AvatarVariants = 'circle' | 'rounded' | 'square'; 40 | 41 | export interface AvatarProps extends HTMLAttributes, ChildrenProp, SxProp { 42 | /** Function to overwrite getting avatar initials. */ 43 | getInitials?: (name: string) => string; 44 | /** The avatars fallback icon when the src is not loaded or specified. */ 45 | icon?: React.ReactElement; 46 | /** Name of the person the avatar represents. */ 47 | name?: string; 48 | /** If `true` the Avatar will show a border around it. */ 49 | showBorder?: boolean; 50 | /** Image url of the Avatar. */ 51 | src?: string; 52 | /** Size of the avatar. */ 53 | size?: LiteralUnion; 54 | /** Variant of the avatar. */ 55 | variant?: LiteralUnion; 56 | } 57 | 58 | export const Avatar = React.forwardRef((props, ref) => { 59 | const { 60 | children, 61 | sx, 62 | getInitials = defaultGetInitials, 63 | icon = , 64 | name, 65 | showBorder, 66 | size, 67 | src, 68 | variant, 69 | ...rest 70 | } = props; 71 | 72 | const styles = useComponentStyles('Avatar', props); 73 | 74 | return ( 75 | 76 | 77 | {children} 78 | 79 | ); 80 | }); 81 | 82 | Avatar.defaultProps = { 83 | size: 'md', 84 | variant: 'circle', 85 | }; 86 | 87 | Avatar.displayName = 'Avatar'; 88 | -------------------------------------------------------------------------------- /src/components/Avatar/AvatarGroup.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Avatar, AvatarGroup, AvatarGroupProps } from '..'; 4 | 5 | export default { 6 | title: 'Avatar Group', 7 | component: AvatarGroup, 8 | } as Meta; 9 | 10 | export const Usage: Story = (props) => ( 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | ); 20 | Usage.args = { 21 | max: 3, 22 | }; 23 | -------------------------------------------------------------------------------- /src/components/Avatar/AvatarGroup.tsx: -------------------------------------------------------------------------------- 1 | import { SpaceProps } from '@spicy-ui/styled-system'; 2 | import * as React from 'react'; 3 | import { SxProp, useComponentStyles } from '../../system'; 4 | import { AsProp, ChildrenProp, HTMLAttributes } from '../../types'; 5 | import { Box } from '../Box'; 6 | import { AvatarProps } from './Avatar'; 7 | 8 | export interface AvatarGroupProps extends HTMLAttributes, AsProp, ChildrenProp, SxProp { 9 | /** Border color of all avatars. */ 10 | borderColor?: string; 11 | /** Maximum number of avatars to show. */ 12 | max?: number; 13 | /** Spacing between avatars. */ 14 | spacing?: SpaceProps['margin']; 15 | /** Size of all avatars. */ 16 | size?: AvatarProps['size']; 17 | /** Variant of all avatars. */ 18 | variant?: AvatarProps['variant']; 19 | } 20 | 21 | export const AvatarGroup = React.forwardRef((props, ref) => { 22 | const { children, sx, borderColor, max, size, spacing, variant, ...rest } = props; 23 | 24 | const styles = useComponentStyles('Avatar', { ...props, showBorder: true }); 25 | 26 | const validChildren = React.Children.toArray(children).filter((child) => 27 | React.isValidElement(child), 28 | ) as React.ReactElement[]; 29 | 30 | const visibleChildren = max ? validChildren.slice(0, max) : validChildren; 31 | 32 | const reversedVisible = visibleChildren.reverse(); 33 | 34 | const overflow = max != null && validChildren.length - max; 35 | 36 | return ( 37 | 38 | {overflow > 0 && ( 39 | 40 | +{overflow} 41 | 42 | )} 43 | {reversedVisible.map((avatar, index) => 44 | React.cloneElement(avatar, { 45 | showBorder: true, 46 | sx: { 47 | mr: index === 0 ? 0 : spacing, 48 | ...(borderColor ? { borderColor } : {}), 49 | ...avatar.props.sx, 50 | }, 51 | size, 52 | variant, 53 | }), 54 | )} 55 | 56 | ); 57 | }); 58 | 59 | AvatarGroup.defaultProps = { 60 | spacing: '-0.75rem', 61 | variant: 'circle', 62 | size: 'md', 63 | }; 64 | 65 | AvatarGroup.displayName = 'AvatarGroup'; 66 | -------------------------------------------------------------------------------- /src/components/Avatar/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Avatar'; 2 | export * from './AvatarGroup'; 3 | -------------------------------------------------------------------------------- /src/components/Badge/Badge.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { uid } from 'react-uid'; 4 | import { Avatar, Badge, BadgeColors, BadgeProps, BadgeVariants, Box, Flex, Text } from '..'; 5 | 6 | const badgeColors: BadgeColors[] = [ 7 | 'blueGray', 8 | 'coolGray', 9 | 'gray', 10 | 'trueGray', 11 | 'warmGray', 12 | 'red', 13 | 'orange', 14 | 'amber', 15 | 'yellow', 16 | 'lime', 17 | 'green', 18 | 'emerald', 19 | 'teal', 20 | 'cyan', 21 | 'lightBlue', 22 | 'blue', 23 | 'indigo', 24 | 'violet', 25 | 'purple', 26 | 'fuchsia', 27 | 'pink', 28 | 'rose', 29 | 'whiteAlpha', 30 | 'blackAlpha', 31 | ]; 32 | 33 | const badgeVariants: BadgeVariants[] = ['outline', 'solid', 'subtle']; 34 | 35 | export default { 36 | title: 'Badge', 37 | component: Badge, 38 | } as Meta; 39 | 40 | export const Usage: Story = (props) => Success; 41 | 42 | export const Colors: Story = (props) => ( 43 | 44 | 45 | 46 | 47 | {badgeVariants.map((variant, idx) => ( 48 | 51 | ))} 52 | 53 | 54 | 55 | {badgeColors.map((color, idx) => ( 56 | 57 | 60 | {badgeVariants.map((variant, idy) => ( 61 | 66 | ))} 67 | 68 | ))} 69 | 70 |
  49 | {variant} 50 |
58 | {color} 59 | 62 | 63 | Badge 64 | 65 |
71 | ); 72 | 73 | export const Composition: Story = () => ( 74 | 75 | 76 | 77 | 78 | Michael Scott 79 | 80 | New 81 | 82 | 83 | Regional Manager 84 | 85 | 86 | ); 87 | 88 | export const FontSize: Story = () => ( 89 | 90 | Michael Scott 91 | 92 | New 93 | 94 | 95 | ); 96 | -------------------------------------------------------------------------------- /src/components/Badge/Badge.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SxProp, useComponentStyles } from '../../system'; 3 | import { ColorScales } from '../../theme'; 4 | import { AsProp, ChildrenProp, HTMLAttributes, LiteralUnion } from '../../types'; 5 | import { Box } from '../Box'; 6 | 7 | export type BadgeColors = ColorScales; 8 | 9 | export type BadgeVariants = 'outline' | 'solid' | 'subtle'; 10 | 11 | export interface BadgeProps extends HTMLAttributes, AsProp, ChildrenProp, SxProp { 12 | /** Color of the badge. */ 13 | color?: LiteralUnion; 14 | /** Variant of the badge. */ 15 | variant?: LiteralUnion; 16 | } 17 | 18 | export const Badge = React.forwardRef((props, ref) => { 19 | const { as, children, sx, color, variant, ...rest } = props; 20 | 21 | const styles = useComponentStyles('Badge', props); 22 | 23 | return ( 24 | 25 | {children} 26 | 27 | ); 28 | }); 29 | 30 | Badge.defaultProps = { 31 | color: 'gray', 32 | variant: 'subtle', 33 | }; 34 | 35 | Badge.displayName = 'Badge'; 36 | -------------------------------------------------------------------------------- /src/components/Badge/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Badge'; 2 | -------------------------------------------------------------------------------- /src/components/Box/Box.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Box, BoxProps } from '..'; 4 | 5 | export default { 6 | title: 'Box', 7 | component: Box, 8 | } as Meta; 9 | 10 | export const Usage: Story = (props) => A Box 📦; 11 | -------------------------------------------------------------------------------- /src/components/Box/Box.tsx: -------------------------------------------------------------------------------- 1 | import { shouldForwardProp } from '@spicy-ui/styled-system'; 2 | import styled from 'styled-components'; 3 | import { allSystem, AllSystemProps, sxMixin, SxProp } from '../../system'; 4 | import { AsProp, ChildrenProp, HTMLAttributes } from '../../types'; 5 | 6 | export interface BoxProps extends HTMLAttributes, AsProp, ChildrenProp, AllSystemProps, SxProp { 7 | color?: any; 8 | } 9 | 10 | export const Box = styled.div.withConfig({ shouldForwardProp })(sxMixin, allSystem); 11 | 12 | Box.displayName = 'Box'; 13 | -------------------------------------------------------------------------------- /src/components/Box/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Box'; 2 | -------------------------------------------------------------------------------- /src/components/Button/Button.tsx: -------------------------------------------------------------------------------- 1 | import { SpaceProps } from '@spicy-ui/styled-system'; 2 | import * as React from 'react'; 3 | import { SxProp, useComponentStyles } from '../../system'; 4 | import { ColorScales } from '../../theme'; 5 | import { AsProp, ChildrenProp, LiteralUnion } from '../../types'; 6 | import { Box } from '../Box'; 7 | import { Spinner } from '../Spinner'; 8 | 9 | interface ButtonSpinnerProps { 10 | hasText: boolean; 11 | spacing?: SpaceProps['margin']; 12 | } 13 | 14 | const ButtonSpinner: React.FC = (props) => { 15 | const { children = } = props; 16 | 17 | const styles = useComponentStyles('ButtonSpinner', props); 18 | 19 | return {children}; 20 | }; 21 | 22 | const iconStyles = { 23 | '& > *': { 24 | display: 'inline-block', 25 | }, 26 | }; 27 | 28 | export type ButtonColors = ColorScales; 29 | 30 | export type ButtonSizes = 'xs' | 'sm' | 'md' | 'lg'; 31 | 32 | export type ButtonVariants = 'filled' | 'outlined' | 'ghost' | 'link' | 'unstyled'; 33 | 34 | export interface ButtonProps extends React.ButtonHTMLAttributes, AsProp, ChildrenProp, SxProp { 35 | /** Space between the button icon and label. */ 36 | iconSpacing?: string; 37 | /** Icon shown before the button's label. */ 38 | iconBefore?: React.ReactElement; 39 | /** Icon shown after the button's label. */ 40 | iconAfter?: React.ReactElement; 41 | /** If `true`, the button will add the `data-active` attribute. */ 42 | isActive?: boolean; 43 | /** If `true`, the button will be disabled. */ 44 | isDisabled?: boolean; 45 | /** If `true`, the button will show a spinner. */ 46 | isLoading?: boolean; 47 | /** If `true`, the button will take up the full width of its container. */ 48 | isFullWidth?: boolean; 49 | /** The label to be shown beside the spinner when `isLoading` is `true`. */ 50 | loadingText?: string; 51 | /** Button `type`. */ 52 | type?: 'submit' | 'reset' | 'button'; 53 | /** Replacement spinner component for when `isLoading` is set to `true` */ 54 | spinner?: React.ReactElement; 55 | /** Color of the button. */ 56 | color?: LiteralUnion; 57 | /** Size of the button. */ 58 | size?: LiteralUnion; 59 | /** Variant style of the button. */ 60 | variant?: LiteralUnion; 61 | } 62 | 63 | export const Button = React.forwardRef((props, ref) => { 64 | const { 65 | as, 66 | children, 67 | sx, 68 | iconSpacing, 69 | iconBefore, 70 | iconAfter, 71 | isActive, 72 | isDisabled, 73 | isLoading, 74 | loadingText, 75 | spinner, 76 | type, 77 | color, 78 | size, 79 | variant, 80 | ...rest 81 | } = props; 82 | 83 | const styles = useComponentStyles('Button', props); 84 | 85 | return ( 86 | 97 | {iconBefore && !isLoading && ( 98 | 99 | {iconBefore} 100 | 101 | )} 102 | {isLoading && ( 103 | 104 | {spinner} 105 | 106 | )} 107 | {isLoading ? ( 108 | loadingText || ( 109 | 110 | {children} 111 | 112 | ) 113 | ) : ( 114 | 115 | {children} 116 | 117 | )} 118 | {iconAfter && !isLoading && ( 119 | 120 | {iconAfter} 121 | 122 | )} 123 | 124 | ); 125 | }); 126 | 127 | Button.defaultProps = { 128 | iconSpacing: '0.5rem', 129 | type: 'button', 130 | color: 'gray', 131 | size: 'md', 132 | variant: 'filled', 133 | }; 134 | 135 | Button.displayName = 'Button'; 136 | -------------------------------------------------------------------------------- /src/components/Button/IconButton.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { HiSearch } from 'react-icons/hi'; 4 | import { IconButton, IconButtonProps, Stack } from '..'; 5 | 6 | export default { 7 | title: 'IconButton', 8 | component: IconButton, 9 | } as Meta; 10 | 11 | export const Usage: Story = (props) => } />; 12 | 13 | export const Colors: Story = () => } />; 14 | 15 | export const Sizes: Story = () => ( 16 | 17 | } /> 18 | } /> 19 | } /> 20 | } /> 21 | 22 | ); 23 | 24 | export const Variants: Story = () => ( 25 | 26 | } /> 27 | } /> 28 | } /> 29 | } /> 30 | } /> 31 | 32 | ); 33 | 34 | export const Loading: Story = () => ( 35 | 36 | } /> 37 | 38 | ); 39 | -------------------------------------------------------------------------------- /src/components/Button/IconButton.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { useComponentStyles } from '../../system'; 3 | import { Button, ButtonProps } from './Button'; 4 | 5 | export interface IconButtonProps 6 | extends Omit { 7 | /** Icon shown inside the button. */ 8 | icon?: React.ReactElement; 9 | /** If `true`, the icon button will be rounded. */ 10 | isRound?: boolean; 11 | } 12 | 13 | export const IconButton = React.forwardRef((props, ref) => { 14 | const { children, sx, icon, isRound, ...rest } = props; 15 | 16 | const styles = useComponentStyles('IconButton', props); 17 | 18 | return ( 19 | 22 | ); 23 | }); 24 | 25 | IconButton.displayName = 'IconButton'; 26 | -------------------------------------------------------------------------------- /src/components/Button/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Button'; 2 | export * from './IconButton'; 3 | -------------------------------------------------------------------------------- /src/components/Checkbox/Checkbox.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { uid } from 'react-uid'; 4 | import { Checkbox, CheckboxColors, CheckboxProps, Stack } from '..'; 5 | 6 | const checkboxColors: CheckboxColors[] = [ 7 | 'blueGray', 8 | 'coolGray', 9 | 'gray', 10 | 'trueGray', 11 | 'warmGray', 12 | 'red', 13 | 'orange', 14 | 'amber', 15 | 'yellow', 16 | 'lime', 17 | 'green', 18 | 'emerald', 19 | 'teal', 20 | 'cyan', 21 | 'lightBlue', 22 | 'blue', 23 | 'indigo', 24 | 'violet', 25 | 'purple', 26 | 'fuchsia', 27 | 'pink', 28 | 'rose', 29 | 'whiteAlpha', 30 | 'blackAlpha', 31 | ]; 32 | 33 | export default { 34 | title: 'Checkbox', 35 | component: Checkbox, 36 | } as Meta; 37 | 38 | export const Usage: Story = (props) => { 39 | const [isChecked, setIsChecked] = React.useState(false); 40 | 41 | return setIsChecked(Boolean(target.checked))} />; 42 | }; 43 | Usage.args = { 44 | label: 'Checkbox', 45 | }; 46 | 47 | export const Colors: Story = () => ( 48 | 49 | {checkboxColors.map((color, idx) => ( 50 | 51 | ))} 52 | 53 | ); 54 | 55 | export const Sizes: Story = () => ( 56 | 57 | 58 | 59 | 60 | 61 | 62 | ); 63 | -------------------------------------------------------------------------------- /src/components/Checkbox/Checkbox.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { useComponentStyles } from '../../system'; 3 | import { ColorScales } from '../../theme'; 4 | import { LiteralUnion } from '../../types'; 5 | import { Box } from '../Box'; 6 | import { Text } from '../Text'; 7 | 8 | export type CheckboxColors = ColorScales; 9 | 10 | export type CheckboxSizes = 'xs' | 'sm' | 'md' | 'lg'; 11 | 12 | export interface CheckboxProps extends Omit, 'width' | 'height' | 'size'> { 13 | /** Checkbox label. */ 14 | label?: string; 15 | /** If `true`, the checkbox will be disabled. */ 16 | isDisabled?: boolean; 17 | /** If `true`, the checkbox will be marked as invalid. */ 18 | isInvalid?: boolean; 19 | /** Color of the checkbox. */ 20 | color?: LiteralUnion; 21 | /** Size of the checkbox. */ 22 | size?: LiteralUnion; 23 | } 24 | 25 | export const Checkbox = React.forwardRef((props, ref) => { 26 | const { id, name, value, label, checked, isDisabled, isInvalid, color, size, ...rest } = props; 27 | 28 | const outerStyles = useComponentStyles('CheckboxOuter', props); 29 | const inputStyles = useComponentStyles('CheckboxInput', props); 30 | const labelStyles = useComponentStyles('CheckboxLabel', props); 31 | 32 | return ( 33 | 34 | 47 | {label && ( 48 | 49 | {label} 50 | 51 | )} 52 | 53 | ); 54 | }); 55 | 56 | Checkbox.defaultProps = { 57 | color: 'blue', 58 | size: 'md', 59 | }; 60 | 61 | Checkbox.displayName = 'Checkbox'; 62 | -------------------------------------------------------------------------------- /src/components/Checkbox/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Checkbox'; 2 | -------------------------------------------------------------------------------- /src/components/CloseButton/CloseButton.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { CloseButton, CloseButtonProps } from '..'; 4 | 5 | export default { 6 | title: 'Close Button', 7 | component: CloseButton, 8 | } as Meta; 9 | 10 | export const Usage: Story = (props) => ; 11 | -------------------------------------------------------------------------------- /src/components/CloseButton/CloseButton.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { HiX } from 'react-icons/hi'; 3 | import { useComponentStyles } from '../../system'; 4 | import { IconButton, IconButtonProps } from '../Button'; 5 | 6 | export interface CloseButtonProps extends Omit { 7 | children?: never; 8 | /** Icon shown inside the close button. */ 9 | icon?: React.ReactElement; 10 | } 11 | 12 | export const CloseButton = React.forwardRef((props, ref) => { 13 | const { sx, icon = , ...rest } = props; 14 | 15 | const styles = useComponentStyles('CloseButton', props); 16 | 17 | return ; 18 | }); 19 | 20 | CloseButton.defaultProps = { 21 | color: 'blackAlpha', 22 | variant: 'ghost', 23 | }; 24 | 25 | CloseButton.displayName = 'CloseButton'; 26 | -------------------------------------------------------------------------------- /src/components/CloseButton/index.ts: -------------------------------------------------------------------------------- 1 | export * from './CloseButton'; 2 | -------------------------------------------------------------------------------- /src/components/Code/Code.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { uid } from 'react-uid'; 4 | import { Code, CodeProps } from '..'; 5 | import { CodeColors, CodeVariants } from './Code'; 6 | 7 | const codeColors: CodeColors[] = [ 8 | 'blueGray', 9 | 'coolGray', 10 | 'gray', 11 | 'trueGray', 12 | 'warmGray', 13 | 'red', 14 | 'orange', 15 | 'amber', 16 | 'yellow', 17 | 'lime', 18 | 'green', 19 | 'emerald', 20 | 'teal', 21 | 'cyan', 22 | 'lightBlue', 23 | 'blue', 24 | 'indigo', 25 | 'violet', 26 | 'purple', 27 | 'fuchsia', 28 | 'pink', 29 | 'rose', 30 | 'whiteAlpha', 31 | 'blackAlpha', 32 | ]; 33 | 34 | const codeVariants: CodeVariants[] = ['outline', 'solid', 'subtle']; 35 | 36 | export default { 37 | title: 'Code', 38 | component: Code, 39 | } as Meta; 40 | 41 | export const Usage: Story = (props) => console.log('hello world!'); 42 | 43 | export const Colors: Story = (props) => ( 44 | 45 | 46 | 47 | 48 | {codeVariants.map((variant, idx) => ( 49 | 52 | ))} 53 | 54 | 55 | 56 | {codeColors.map((color, idx) => ( 57 | 58 | 61 | {codeVariants.map((variant, idy) => ( 62 | 67 | ))} 68 | 69 | ))} 70 | 71 |
  50 | {variant} 51 |
59 | {color} 60 | 63 | 64 | console.log('hello world!') 65 | 66 |
72 | ); 73 | -------------------------------------------------------------------------------- /src/components/Code/Code.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SxProp, useComponentStyles } from '../../system'; 3 | import { ColorScales } from '../../theme'; 4 | import { AsProp, ChildrenProp, HTMLAttributes, LiteralUnion } from '../../types'; 5 | import { Box } from '../Box'; 6 | 7 | export type CodeColors = ColorScales; 8 | 9 | export type CodeVariants = 'outline' | 'solid' | 'subtle'; 10 | 11 | export interface CodeProps extends HTMLAttributes, AsProp, ChildrenProp, SxProp { 12 | /** Color of the code element. */ 13 | color?: LiteralUnion; 14 | /** Variant of the code element. */ 15 | variant?: LiteralUnion; 16 | } 17 | 18 | export const Code = React.forwardRef((props, ref) => { 19 | const { as, children, sx, color, variant, ...rest } = props; 20 | 21 | const styles = useComponentStyles('Code', props); 22 | 23 | return ( 24 | 25 | {children} 26 | 27 | ); 28 | }); 29 | 30 | Code.defaultProps = { 31 | color: 'gray', 32 | variant: 'subtle', 33 | }; 34 | 35 | Code.displayName = 'Code'; 36 | -------------------------------------------------------------------------------- /src/components/Code/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Code'; 2 | -------------------------------------------------------------------------------- /src/components/Container/Container.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Container, ContainerProps, Box } from '..'; 4 | 5 | export default { 6 | title: 'Container', 7 | component: Container, 8 | } as Meta; 9 | 10 | export const Usage: Story = (props) => ( 11 | 12 | 13 | Container inner 14 | 15 | 16 | ); 17 | 18 | export const Centered: Story = (props) => ( 19 | 20 | 21 | Container inner 22 | 23 | 24 | ); 25 | Centered.args = { isCentered: true }; 26 | -------------------------------------------------------------------------------- /src/components/Container/Container.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { useComponentStyles } from '../../system'; 3 | import { Box, BoxProps } from '../Box'; 4 | 5 | export interface ContainerProps extends BoxProps { 6 | /** If `true`, container will center its children. */ 7 | isCentered?: boolean; 8 | } 9 | 10 | export const Container = React.forwardRef((props, ref) => { 11 | const { as, children, sx, isCentered, ...rest } = props; 12 | 13 | const styles = useComponentStyles('Container', props); 14 | 15 | return ( 16 | 17 | {children} 18 | 19 | ); 20 | }); 21 | 22 | Container.displayName = 'Container'; 23 | -------------------------------------------------------------------------------- /src/components/Container/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Container'; 2 | -------------------------------------------------------------------------------- /src/components/Divider/Divider.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Divider, DividerProps, Stack } from '..'; 4 | 5 | export default { 6 | title: 'Divider', 7 | component: Divider, 8 | } as Meta; 9 | 10 | export const Usage: Story = (props) => ; 11 | 12 | export const Vertical: Story = () => ( 13 | 14 |
one
15 | 16 |
two
17 |
18 | ); 19 | 20 | export const Stylised: Story = () => ( 21 | 28 | ); 29 | -------------------------------------------------------------------------------- /src/components/Divider/Divider.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SxProp, useComponentStyles } from '../../system'; 3 | import { AsProp, HTMLAttributes, LiteralUnion } from '../../types'; 4 | import { Box } from '../Box'; 5 | 6 | export type DividerOrientation = 'horizontal' | 'vertical'; 7 | 8 | export interface DividerProps extends HTMLAttributes, AsProp, SxProp { 9 | /** Orientation of the divider. */ 10 | orientation?: LiteralUnion; 11 | } 12 | 13 | export const Divider = React.forwardRef((props, ref) => { 14 | const { sx, orientation, ...rest } = props; 15 | 16 | const styles = useComponentStyles('Divider', props); 17 | 18 | return ; 19 | }); 20 | 21 | Divider.defaultProps = { 22 | orientation: 'horizontal', 23 | }; 24 | 25 | Divider.displayName = 'Divider'; 26 | -------------------------------------------------------------------------------- /src/components/Divider/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Divider'; 2 | -------------------------------------------------------------------------------- /src/components/Drawer/Drawer.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Box, Button, Drawer, DrawerProps } from '..'; 4 | import { useDisclosure } from '../../hooks'; 5 | 6 | export default { 7 | title: 'Drawer', 8 | component: Drawer, 9 | } as Meta; 10 | 11 | export const Usage: Story = (props) => { 12 | const { isOpen, onClose, onOpen } = useDisclosure(); 13 | 14 | return ( 15 | <> 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | ); 26 | }; 27 | -------------------------------------------------------------------------------- /src/components/Drawer/Drawer.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import FocusLock from 'react-focus-lock'; 3 | import { useKeyPress } from '../../hooks'; 4 | import { SxProp, useComponentStyles } from '../../system'; 5 | import { AsProp, ChildrenProp, LiteralUnion } from '../../types'; 6 | import { Box } from '../Box'; 7 | import { Overlay } from '../Overlay'; 8 | 9 | export type DrawerAnchor = 'left' | 'right' | 'top' | 'bottom'; 10 | 11 | export type DrawerSize = 'xs' | 'sm' | 'md' | 'lg'; 12 | 13 | const getAnchor = (anchor?: DrawerAnchor) => { 14 | switch (anchor) { 15 | case 'top': 16 | return { 17 | top: 0, 18 | right: 0, 19 | bottom: 'unset', 20 | left: 0, 21 | }; 22 | case 'right': 23 | return { 24 | top: 0, 25 | right: 0, 26 | bottom: 0, 27 | left: 'unset', 28 | }; 29 | case 'bottom': 30 | return { 31 | top: 'unset', 32 | right: 0, 33 | bottom: 0, 34 | left: 0, 35 | }; 36 | default: 37 | return { 38 | top: 0, 39 | right: 'unset', 40 | bottom: 0, 41 | left: 0, 42 | }; 43 | } 44 | }; 45 | 46 | export interface DrawerProps extends AsProp, ChildrenProp, SxProp { 47 | isOpen: boolean; 48 | onClose?: () => void; 49 | anchor?: DrawerAnchor; 50 | closeOnEsc?: boolean; 51 | closeOnOverlayClick?: boolean; 52 | disableFocusTrap?: boolean; 53 | size?: LiteralUnion; 54 | } 55 | 56 | export const Drawer: React.FC = (props) => { 57 | const { children, sx, isOpen, onClose, anchor, closeOnEsc, closeOnOverlayClick, disableFocusTrap, size, ...rest } = 58 | props; 59 | 60 | useKeyPress('Escape', () => { 61 | if (isOpen && !closeOnEsc && onClose) { 62 | onClose(); 63 | } 64 | }); 65 | 66 | const onOverlayClick = React.useCallback( 67 | (e: React.MouseEvent) => { 68 | if (e.target !== e.currentTarget) { 69 | return; 70 | } 71 | 72 | if (closeOnOverlayClick && onClose) { 73 | onClose(); 74 | } 75 | }, 76 | [closeOnOverlayClick, onClose], 77 | ); 78 | 79 | React.useEffect(() => { 80 | if (isOpen && !document.body.classList.contains('noscroll')) { 81 | document.body.classList.add('noscroll'); 82 | } 83 | 84 | return () => document.body.classList.remove('noscroll'); 85 | }, [isOpen]); 86 | 87 | const style = useComponentStyles('Drawer', props); 88 | 89 | return ( 90 | 91 | 92 | 93 | {children} 94 | 95 | 96 | 97 | ); 98 | }; 99 | 100 | Drawer.defaultProps = { 101 | anchor: 'right', 102 | closeOnOverlayClick: true, 103 | size: 'xs', 104 | }; 105 | 106 | Drawer.displayName = 'Drawer'; 107 | -------------------------------------------------------------------------------- /src/components/Drawer/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Drawer'; 2 | -------------------------------------------------------------------------------- /src/components/Flex/Flex.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Box, Flex, FlexProps } from '..'; 4 | 5 | export default { 6 | title: 'Flex', 7 | component: Flex, 8 | } as Meta; 9 | 10 | export const Usage: Story = (props) => ( 11 | 12 | 13 | Box 1 14 | 15 | 16 | Box 2 17 | 18 | 19 | Box 3 20 | 21 | 22 | Box 4 23 | 24 | 25 | Box 5 26 | 27 | 28 | Box 6 29 | 30 | 31 | ); 32 | -------------------------------------------------------------------------------- /src/components/Flex/Flex.tsx: -------------------------------------------------------------------------------- 1 | import { extendedFlexbox, ExtendedFlexboxProps, shouldForwardProp } from '@spicy-ui/styled-system'; 2 | import styled from 'styled-components'; 3 | import { allSystem, sxMixin } from '../../system'; 4 | import { BoxProps } from '../Box'; 5 | 6 | export interface FlexProps extends BoxProps, ExtendedFlexboxProps {} 7 | 8 | export const Flex = styled.div.withConfig({ shouldForwardProp })(sxMixin, allSystem, extendedFlexbox); 9 | 10 | Flex.defaultProps = { 11 | display: 'flex', 12 | }; 13 | 14 | Flex.displayName = 'Flex'; 15 | -------------------------------------------------------------------------------- /src/components/Flex/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Flex'; 2 | -------------------------------------------------------------------------------- /src/components/Grid/Grid.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Box, Grid, GridProps } from '..'; 4 | 5 | export default { 6 | title: 'Grid', 7 | component: Grid, 8 | } as Meta; 9 | 10 | export const Usage: Story = (props) => ( 11 | 12 | 13 | Box 1 14 | 15 | 16 | Box 2 17 | 18 | 19 | Box 3 20 | 21 | 22 | Box 4 23 | 24 | 25 | Box 5 26 | 27 | 28 | Box 6 29 | 30 | 31 | ); 32 | Usage.args = { 33 | gap: 4, 34 | templateColumns: 'repeat(6, 1fr)', 35 | }; 36 | -------------------------------------------------------------------------------- /src/components/Grid/Grid.tsx: -------------------------------------------------------------------------------- 1 | import { extendedGrid, ExtendedGridProps, shouldForwardProp } from '@spicy-ui/styled-system'; 2 | import styled from 'styled-components'; 3 | import { allSystem, sxMixin } from '../../system'; 4 | import { BoxProps } from '../Box'; 5 | 6 | export interface GridProps extends BoxProps, ExtendedGridProps {} 7 | 8 | export const Grid = styled.div.withConfig({ shouldForwardProp })(sxMixin, allSystem, extendedGrid); 9 | 10 | Grid.defaultProps = { 11 | display: 'grid', 12 | }; 13 | 14 | Grid.displayName = 'Grid'; 15 | -------------------------------------------------------------------------------- /src/components/Grid/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Grid'; 2 | -------------------------------------------------------------------------------- /src/components/Heading/Heading.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { uid } from 'react-uid'; 4 | import { Heading, HeadingProps, Stack } from '..'; 5 | 6 | const headingVariants = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'inherit']; 7 | 8 | export default { 9 | title: 'Heading', 10 | component: Heading, 11 | } as Meta; 12 | 13 | export const Usage: Story = (props) => ( 14 | The quick brown fox jumped over the lazy dog. 15 | ); 16 | 17 | export const Variants: Story = () => ( 18 | 19 | {headingVariants.map((variant, idx) => ( 20 | 21 | {variant}: The quick brown fox jumped over the lazy dog. 22 | 23 | ))} 24 | 25 | ); 26 | -------------------------------------------------------------------------------- /src/components/Heading/Heading.tsx: -------------------------------------------------------------------------------- 1 | import { shouldForwardProp } from '@spicy-ui/styled-system'; 2 | import styled from 'styled-components'; 3 | import { allSystem, AllSystemProps, componentStylesMixin, sxMixin, SxProp } from '../../system'; 4 | import { AsProp, ChildrenProp, HTMLAttributes, LiteralUnion } from '../../types'; 5 | 6 | export type HeadingVariant = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'inherit'; 7 | 8 | export interface HeadingProps extends HTMLAttributes, AsProp, ChildrenProp, AllSystemProps, SxProp { 9 | color?: string; 10 | /** Variant of the heading. */ 11 | variant?: LiteralUnion; 12 | } 13 | 14 | export const Heading = styled.h2.withConfig({ shouldForwardProp })( 15 | componentStylesMixin('Heading'), 16 | sxMixin, 17 | allSystem, 18 | ); 19 | 20 | Heading.defaultProps = { 21 | variant: 'h2', 22 | }; 23 | 24 | Heading.displayName = 'Heading'; 25 | -------------------------------------------------------------------------------- /src/components/Heading/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Heading'; 2 | -------------------------------------------------------------------------------- /src/components/Image/Image.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Image, ImageProps, Spinner } from '..'; 4 | 5 | export default { 6 | title: 'Image', 7 | component: Image, 8 | } as Meta; 9 | 10 | export const Usage: Story = (props) => ; 11 | Usage.args = { 12 | src: 'https://source.unsplash.com/random/256x256?mountain', 13 | alt: 'Random unsplash image', 14 | }; 15 | 16 | export const Fallback: Story = (props) => ; 17 | Fallback.args = { 18 | src: 'https://source.unsplash.com/random/256x256?city', 19 | fallbackSrc: 'https://via.placeholder.com/256', 20 | alt: 'Random unsplash image', 21 | }; 22 | 23 | export const FallbackComponent: Story = (props) => } />; 24 | FallbackComponent.args = { 25 | src: 'https://source.unsplash.com/random/256x256?forest', 26 | alt: 'Random unsplash image', 27 | }; 28 | -------------------------------------------------------------------------------- /src/components/Image/Image.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { useImage } from '../../hooks/useImage'; 3 | import { SxProp, useComponentStyles } from '../../system'; 4 | import { Box } from '../Box'; 5 | 6 | export interface ImageProps extends React.ImgHTMLAttributes, SxProp { 7 | /** Fallback component for the image. This is shown when the image is loading. */ 8 | fallback?: React.ReactElement; 9 | /** Fallback src image. If you intend to use this instead of a component, it's advised to use a data src. */ 10 | fallbackSrc?: string; 11 | /** Image src. */ 12 | src?: string; 13 | } 14 | 15 | export const Image = React.forwardRef((props, ref) => { 16 | const { sx, crossOrigin, fallback, fallbackSrc, src, ...rest } = props; 17 | 18 | const { status } = useImage(src, crossOrigin); 19 | 20 | const styles = useComponentStyles('Image', props); 21 | 22 | if (status !== 'loaded') { 23 | return fallback || ; 24 | } 25 | 26 | return ; 27 | }); 28 | 29 | Image.displayName = 'Image'; 30 | -------------------------------------------------------------------------------- /src/components/Image/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Image'; 2 | -------------------------------------------------------------------------------- /src/components/Input/Input.stories.tsx: -------------------------------------------------------------------------------- 1 | import { action } from '@storybook/addon-actions'; 2 | import { Meta, Story } from '@storybook/react'; 3 | import * as React from 'react'; 4 | import { Input, InputProps, Stack } from '..'; 5 | 6 | export default { 7 | title: 'Input', 8 | component: Input, 9 | } as Meta; 10 | 11 | export const Usage: Story = (props) => ( 12 | action('onChange')(target.value)} /> 13 | ); 14 | 15 | export const AllSizes: Story = () => ( 16 | 17 | 18 | 19 | 20 | 21 | 22 | ); 23 | 24 | export const AllVariants: Story = () => ( 25 | 26 | 27 | 28 | 29 | 30 | 31 | ); 32 | 33 | // export const Addons = () => ( 34 | // 35 | // 36 | // +64 37 | // 38 | // 39 | // 40 | // 41 | // 42 | // 43 | // 44 | // 45 | // ); 46 | 47 | // export const InnerAddons = () => ( 48 | // 49 | // 50 | // 51 | // 52 | // 53 | // 54 | // 55 | 56 | // 57 | // 58 | // $ 59 | // 60 | // 61 | // 62 | // 63 | // 64 | // 65 | // 66 | // ); 67 | 68 | // export const PasswordExample = () => { 69 | // const [show, setShow] = React.useState(false); 70 | // const handleClick = () => setShow(!show); 71 | 72 | // return ( 73 | // 74 | // 75 | // 76 | // 79 | // 80 | // 81 | // ); 82 | // }; 83 | -------------------------------------------------------------------------------- /src/components/Input/Input.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SxProp, useComponentStyles } from '../../system'; 3 | import { AsProp, ChildrenProp, LiteralUnion } from '../../types'; 4 | import { Box } from '../Box'; 5 | 6 | type InputSizes = 'xs' | 'sm' | 'md' | 'lg'; 7 | 8 | type InputVariants = 'outlined' | 'filled' | 'underlined' | 'unstyled'; 9 | 10 | export interface InputProps 11 | extends Omit, 'width' | 'height' | 'size'>, 12 | AsProp, 13 | ChildrenProp, 14 | SxProp { 15 | /** If `true`, the input will be disabled. */ 16 | isDisabled?: boolean; 17 | /** If `true`, the input will be marked as invalid. */ 18 | isInvalid?: boolean; 19 | /** If `true`, the input will be read only. */ 20 | isReadOnly?: boolean; 21 | /** If `true`, the input will be required. */ 22 | isRequired?: boolean; 23 | /** Size of the input. */ 24 | size?: LiteralUnion; 25 | /** Variant of the input. */ 26 | variant?: LiteralUnion; 27 | } 28 | 29 | export const Input = React.forwardRef((props, ref) => { 30 | const { as, children, sx, isDisabled, isInvalid, isReadOnly, isRequired, size, variant, ...rest } = props; 31 | 32 | const styles = useComponentStyles('Input', props); 33 | 34 | return ( 35 | 44 | {children} 45 | 46 | ); 47 | }); 48 | 49 | Input.defaultProps = { 50 | size: 'md', 51 | type: 'text', 52 | variant: 'outlined', 53 | }; 54 | 55 | Input.displayName = 'Input'; 56 | -------------------------------------------------------------------------------- /src/components/Input/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Input'; 2 | -------------------------------------------------------------------------------- /src/components/Kbd/Kbd.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Kbd, KbdProps, Text } from '..'; 4 | 5 | export default { 6 | title: 'Kbd', 7 | component: Kbd, 8 | } as Meta; 9 | 10 | export const Usage: Story = (props) => ( 11 | 12 | ctrl + shift + v 13 | 14 | ); 15 | -------------------------------------------------------------------------------- /src/components/Kbd/Kbd.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SxProp, useComponentStyles } from '../../system'; 3 | import { AsProp, ChildrenProp, HTMLAttributes } from '../../types'; 4 | import { Box } from '../Box'; 5 | 6 | export interface KbdProps extends HTMLAttributes, AsProp, ChildrenProp, SxProp {} 7 | 8 | export const Kbd = React.forwardRef((props, ref) => { 9 | const { as, children, sx, ...rest } = props; 10 | 11 | const styles = useComponentStyles('Kbd', props); 12 | 13 | return ( 14 | 15 | {children} 16 | 17 | ); 18 | }); 19 | 20 | Kbd.displayName = 'Kbd'; 21 | -------------------------------------------------------------------------------- /src/components/Kbd/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Kbd'; 2 | -------------------------------------------------------------------------------- /src/components/Link/Link.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Link, LinkProps } from '..'; 4 | 5 | export default { 6 | title: 'Link', 7 | component: Link, 8 | } as Meta; 9 | 10 | export const Usage: Story = (props) => 🌶️ Spicy UI; 11 | -------------------------------------------------------------------------------- /src/components/Link/Link.tsx: -------------------------------------------------------------------------------- 1 | import { sfp } from '@spicy-ui/styled-system'; 2 | import * as React from 'react'; 3 | import styled from 'styled-components'; 4 | import { componentStylesMixin, sxMixin, SxProp } from '../../system'; 5 | import { ColorScales } from '../../theme'; 6 | import { AsProp, ChildrenProp, LiteralUnion } from '../../types'; 7 | 8 | export type LinkColors = ColorScales; 9 | 10 | export type LinkUnderlineBehaviour = 'default' | 'none' | 'hover'; 11 | 12 | export interface LinkProps 13 | extends Partial>, 14 | AsProp, 15 | ChildrenProp, 16 | SxProp { 17 | /** Color of the link. */ 18 | color?: LiteralUnion; 19 | /** Hover color of the link. */ 20 | hoverColor?: LiteralUnion; 21 | /** Set to `true` to disable the link. */ 22 | isDisabled?: boolean; 23 | /** Set to `true` to add external `rel` tags. */ 24 | isExternal?: boolean; 25 | /** Underline behaviour of the link. */ 26 | underlineBehaviour?: LinkUnderlineBehaviour; 27 | } 28 | 29 | export const Link = styled.a 30 | .attrs(({ isDisabled, isExternal, onClick }) => ({ 31 | 'aria-disabled': isDisabled || undefined, 32 | 'data-disabled': isDisabled || undefined, 33 | tabIndex: isDisabled ? -1 : undefined, 34 | target: isExternal ? '_blank' : undefined, 35 | role: isExternal ? `noopener noreferrer` : undefined, 36 | onClick: (e: React.MouseEvent) => { 37 | if (isDisabled) { 38 | e.preventDefault(); 39 | return; 40 | } 41 | 42 | if (onClick) { 43 | onClick(e); 44 | } 45 | }, 46 | })) 47 | .withConfig({ 48 | shouldForwardProp: sfp(['color', 'hoverColor', 'isDisabled', 'isExternal', 'underlineBehaviour']), 49 | })(componentStylesMixin('Link'), sxMixin); 50 | 51 | Link.defaultProps = { 52 | underlineBehaviour: 'hover', 53 | }; 54 | 55 | Link.displayName = 'Link'; 56 | -------------------------------------------------------------------------------- /src/components/Link/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Link'; 2 | -------------------------------------------------------------------------------- /src/components/Menu/Menu.tsx: -------------------------------------------------------------------------------- 1 | import { motion, Variants } from 'framer-motion'; 2 | import * as React from 'react'; 3 | import styled from 'styled-components'; 4 | import { PopperProps, useDisclosure, UseDisclosureReturn, usePopper } from '../../hooks'; 5 | import { sxMixin, SxProp, useComponentStyles } from '../../system'; 6 | import { AsProp, ChildrenProp } from '../../types'; 7 | import { runIfFn } from '../../util'; 8 | import { Portal } from '../Portal'; 9 | 10 | const Motion = styled(motion.div)(sxMixin); 11 | 12 | const variants: Variants = { 13 | hidden: { 14 | opacity: 0, 15 | pointerEvents: 'none', 16 | transition: { duration: 0.2 }, 17 | }, 18 | visible: { 19 | opacity: 1, 20 | pointerEvents: 'auto', 21 | transition: { duration: 0.2 }, 22 | }, 23 | }; 24 | 25 | export interface MenuProps extends PopperProps, AsProp, ChildrenProp, SxProp { 26 | trigger: ((props: UseDisclosureReturn) => React.ReactElement) | React.ReactElement; 27 | children: ((props: UseDisclosureReturn) => React.ReactElement) | React.ReactNode; 28 | isFullWidth?: boolean; 29 | openOnHover?: boolean; 30 | } 31 | 32 | export const Menu: React.FC = (props) => { 33 | const { 34 | children, 35 | sx, 36 | trigger, 37 | closeOnBlur, 38 | closeOnEsc, 39 | closeOnInnerClick, 40 | closeOnOuterClick, 41 | openOnHover, 42 | placement, 43 | offset, 44 | ...rest 45 | } = props; 46 | 47 | const styles = useComponentStyles('Menu', props); 48 | 49 | const { isOpen, onOpen, onClose, onToggle } = useDisclosure(); 50 | 51 | const { triggerProps, childProps } = usePopper({ 52 | isOpen, 53 | onClose, 54 | closeOnBlur, 55 | closeOnEsc, 56 | closeOnInnerClick, 57 | closeOnOuterClick, 58 | placement, 59 | offset, 60 | }); 61 | 62 | return ( 63 | <> 64 | {React.cloneElement(runIfFn(trigger, { isOpen, onOpen, onClose, onToggle }), { 65 | ...triggerProps, 66 | onClick: openOnHover ? undefined : onToggle, 67 | onKeyDown: ({ key }: React.KeyboardEvent) => (key === 'Enter' ? onToggle : undefined), 68 | onMouseEnter: openOnHover ? onOpen : undefined, 69 | })} 70 | 71 | 80 | {runIfFn(children, { isOpen, onOpen, onClose, onToggle })} 81 | 82 | 83 | 84 | ); 85 | }; 86 | 87 | Menu.defaultProps = { 88 | closeOnBlur: false, 89 | closeOnEsc: true, 90 | closeOnInnerClick: true, 91 | closeOnOuterClick: true, 92 | openOnHover: false, 93 | placement: 'bottom-start', 94 | offset: [0, 8], 95 | }; 96 | 97 | Menu.displayName = 'Menu'; 98 | -------------------------------------------------------------------------------- /src/components/Menu/MenuDivider.tsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | import { componentStylesMixin, sxMixin, SxProp } from '../../system'; 3 | 4 | export const MenuDivider = styled.div(componentStylesMixin('MenuDivider'), sxMixin); 5 | 6 | MenuDivider.displayName = 'MenuDivider'; 7 | -------------------------------------------------------------------------------- /src/components/Menu/MenuHeader.tsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | import { componentStylesMixin, sxMixin, SxProp } from '../../system'; 3 | 4 | export const MenuHeader = styled.div(componentStylesMixin('MenuHeader'), sxMixin); 5 | 6 | MenuHeader.displayName = 'MenuHeader'; 7 | -------------------------------------------------------------------------------- /src/components/Menu/MenuItem.tsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | import { componentStylesMixin, sxMixin, SxProp } from '../../system'; 3 | 4 | export const MenuItem = styled.div(componentStylesMixin('MenuItem'), sxMixin); 5 | 6 | MenuItem.displayName = 'MenuItem'; 7 | -------------------------------------------------------------------------------- /src/components/Menu/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Menu'; 2 | export * from './MenuDivider'; 3 | export * from './MenuHeader'; 4 | export * from './MenuItem'; 5 | -------------------------------------------------------------------------------- /src/components/Modal/Modal.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { loremIpsum } from 'react-lorem-ipsum'; 4 | import { uid } from 'react-uid'; 5 | import { Button, Modal, ModalBody, ModalCloseButton, ModalFooter, ModalHeader, ModalProps, Stack, Text } from '..'; 6 | import { useDisclosure } from '../../hooks'; 7 | 8 | const lorem = loremIpsum({ p: 2 }).map((str, i) => {str}); 9 | 10 | export default { 11 | title: 'Modal', 12 | component: Modal, 13 | subcomponents: { ModalHeader, ModalBody, ModalFooter, ModalCloseButton }, 14 | } as Meta; 15 | 16 | export const Usage: Story = (props) => { 17 | const { isOpen, onOpen, onClose } = useDisclosure(); 18 | 19 | return ( 20 | <> 21 | 22 | 23 | 24 | 25 | Modal header 26 | 27 | {lorem} 28 | 29 | 30 | 33 | 34 | 35 | 36 | 37 | ); 38 | }; 39 | Usage.args = { 40 | closeOnOverlayClick: true, 41 | }; 42 | 43 | export const AsAlertDialog: Story = (props) => { 44 | const { isOpen, onOpen, onClose } = useDisclosure(); 45 | 46 | return ( 47 | <> 48 | 51 | 52 | 53 | Delete product 54 | Are you sure you want to delete this product? 55 | 56 | 59 | 60 | 61 | 62 | 63 | ); 64 | }; 65 | AsAlertDialog.args = { closeOnOverlayClick: false }; 66 | -------------------------------------------------------------------------------- /src/components/Modal/Modal.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import FocusLock from 'react-focus-lock'; 3 | import { useKeyPress } from '../../hooks'; 4 | import { SxProp, useComponentStyles } from '../../system'; 5 | import { AsProp, ChildrenProp, LiteralUnion } from '../../types'; 6 | import { Box } from '../Box'; 7 | import { Overlay } from '../Overlay'; 8 | 9 | export type ModalSize = 10 | | '3xs' 11 | | '2xs' 12 | | 'xs' 13 | | 'sm' 14 | | 'md' 15 | | 'lg' 16 | | 'xl' 17 | | '2xl' 18 | | '3xl' 19 | | '4xl' 20 | | '5xl' 21 | | '6xl' 22 | | 'full'; 23 | 24 | export interface ModalProps extends AsProp, ChildrenProp, SxProp { 25 | isOpen: boolean; 26 | onClose?: () => void; 27 | size?: LiteralUnion; 28 | closeOnEsc?: boolean; 29 | closeOnOverlayClick?: boolean; 30 | disableFocusTrap?: boolean; 31 | } 32 | 33 | export const Modal: React.FC = (props) => { 34 | const { children, sx, isOpen, onClose, size, closeOnEsc, closeOnOverlayClick, disableFocusTrap, ...rest } = props; 35 | 36 | useKeyPress('Escape', () => { 37 | if (isOpen && closeOnEsc && onClose) { 38 | onClose(); 39 | } 40 | }); 41 | 42 | const onOverlayClick = React.useCallback( 43 | (e: React.MouseEvent) => { 44 | if (e.target !== e.currentTarget) { 45 | return; 46 | } 47 | 48 | if (closeOnOverlayClick && onClose) { 49 | onClose(); 50 | } 51 | }, 52 | [closeOnOverlayClick, onClose], 53 | ); 54 | 55 | React.useEffect(() => { 56 | if (isOpen && !document.body.classList.contains('noscroll')) { 57 | document.body.classList.add('noscroll'); 58 | } 59 | 60 | return () => document.body.classList.remove('noscroll'); 61 | }, [isOpen]); 62 | 63 | const style = useComponentStyles('Modal', props); 64 | 65 | return ( 66 | 67 | 68 | 69 | {children} 70 | 71 | 72 | 73 | ); 74 | }; 75 | 76 | Modal.defaultProps = { 77 | closeOnOverlayClick: true, 78 | size: 'md', 79 | }; 80 | 81 | Modal.displayName = 'Modal'; 82 | -------------------------------------------------------------------------------- /src/components/Modal/ModalBody.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SxProp, useComponentStyles } from '../../system'; 3 | import { AsProp, ChildrenProp } from '../../types'; 4 | import { Box } from '../Box'; 5 | 6 | export interface ModalBodyProps extends AsProp, ChildrenProp, SxProp {} 7 | 8 | export const ModalBody: React.FC = (props) => { 9 | const { children, sx, ...rest } = props; 10 | 11 | const styles = useComponentStyles('ModalBody', props); 12 | 13 | return ( 14 | 15 | {children} 16 | 17 | ); 18 | }; 19 | 20 | ModalBody.displayName = 'ModalBody'; 21 | -------------------------------------------------------------------------------- /src/components/Modal/ModalCloseButton.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { useComponentStyles } from '../../system'; 3 | import { CloseButton, CloseButtonProps } from '../CloseButton'; 4 | 5 | export interface ModalCloseButtonProps extends CloseButtonProps {} 6 | 7 | export const ModalCloseButton: React.FC = (props) => { 8 | const { sx, ...rest } = props; 9 | 10 | const styles = useComponentStyles('ModalCloseButton', props); 11 | 12 | return ; 13 | }; 14 | 15 | ModalCloseButton.displayName = 'ModalCloseButton'; 16 | -------------------------------------------------------------------------------- /src/components/Modal/ModalFooter.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SxProp, useComponentStyles } from '../../system'; 3 | import { AsProp, ChildrenProp } from '../../types'; 4 | import { Box } from '../Box'; 5 | 6 | export interface ModalFooterProps extends AsProp, ChildrenProp, SxProp {} 7 | 8 | export const ModalFooter: React.FC = (props) => { 9 | const { children, sx, ...rest } = props; 10 | 11 | const styles = useComponentStyles('ModalFooter', props); 12 | 13 | return ( 14 | 15 | {children} 16 | 17 | ); 18 | }; 19 | 20 | ModalFooter.displayName = 'ModalFooter'; 21 | -------------------------------------------------------------------------------- /src/components/Modal/ModalHeader.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SxProp, useComponentStyles } from '../../system'; 3 | import { AsProp, ChildrenProp } from '../../types'; 4 | import { Box } from '../Box'; 5 | 6 | export interface ModalHeaderProps extends AsProp, ChildrenProp, SxProp {} 7 | 8 | export const ModalHeader: React.FC = (props) => { 9 | const { children, sx, ...rest } = props; 10 | 11 | const styles = useComponentStyles('ModalHeader', props); 12 | 13 | return ( 14 | 15 | {children} 16 | 17 | ); 18 | }; 19 | 20 | ModalHeader.displayName = 'ModalHeader'; 21 | -------------------------------------------------------------------------------- /src/components/Modal/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Modal'; 2 | export * from './ModalBody'; 3 | export * from './ModalCloseButton'; 4 | export * from './ModalFooter'; 5 | export * from './ModalHeader'; 6 | -------------------------------------------------------------------------------- /src/components/Overlay/Overlay.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Button, Overlay, OverlayProps, Text } from '..'; 4 | import { useDisclosure } from '../../hooks'; 5 | 6 | export default { 7 | title: 'Overlay', 8 | component: Overlay, 9 | } as Meta; 10 | 11 | export const Usage: Story = () => { 12 | const { isOpen, onOpen, onClose } = useDisclosure(); 13 | 14 | return ( 15 | <> 16 | 17 | 18 | 19 | Overlay inner 20 | 21 | 22 | ); 23 | }; 24 | -------------------------------------------------------------------------------- /src/components/Overlay/Overlay.tsx: -------------------------------------------------------------------------------- 1 | import { motion, Variants } from 'framer-motion'; 2 | import * as React from 'react'; 3 | import styled from 'styled-components'; 4 | import { sxMixin, SxProp, useComponentStyles } from '../../system'; 5 | import { AsProp, ChildrenProp } from '../../types'; 6 | import { Portal } from '../Portal'; 7 | 8 | const Motion = styled(motion.div)(sxMixin); 9 | 10 | const variants: Variants = { 11 | hidden: { 12 | opacity: 0, 13 | pointerEvents: 'none', 14 | transition: { duration: 0.3 }, 15 | }, 16 | visible: { 17 | opacity: 1, 18 | pointerEvents: 'auto', 19 | transition: { duration: 0.2 }, 20 | }, 21 | }; 22 | export interface OverlayProps extends AsProp, ChildrenProp, SxProp { 23 | isOpen: boolean; 24 | onClick?: React.MouseEventHandler; 25 | } 26 | 27 | export const Overlay: React.FC = (props) => { 28 | const { children, sx, isOpen, onClick, ...rest } = props; 29 | 30 | const style = useComponentStyles('Overlay', props); 31 | 32 | return ( 33 | 34 | 42 | {children} 43 | 44 | 45 | ); 46 | }; 47 | 48 | Overlay.displayName = 'Overlay'; 49 | -------------------------------------------------------------------------------- /src/components/Overlay/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Overlay'; 2 | -------------------------------------------------------------------------------- /src/components/Portal/Portal.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { HiMinusCircle, HiPlusCircle } from 'react-icons/hi'; 4 | import { Box, Button, Input, Portal, PortalProps, Stack } from '..'; 5 | 6 | export default { 7 | title: 'Portal', 8 | component: Portal, 9 | } as Meta; 10 | 11 | export const Usage: Story = () => ( 12 | 13 | 14 | I'm a box inside a portal! 15 | 16 | 17 | ); 18 | 19 | export const ContentRerender: Story = () => { 20 | const [value, setValue] = React.useState(0); 21 | const [amount, setAmount] = React.useState(10); 22 | 23 | const increment = React.useCallback(() => setValue((prev) => prev + amount), [amount]); 24 | const decrement = React.useCallback(() => setValue((prev) => prev - amount), [amount]); 25 | 26 | return ( 27 | <> 28 | 29 | 32 | setAmount(Number.parseInt(target.value, 10))} 37 | /> 38 | 41 | 42 | 43 | 44 | value = {value} 45 | 46 | 47 | 48 | 49 | value = {value} 50 | 51 | 52 | 53 | 54 | value = {value} 55 | 56 | 57 | 58 | 59 | value = {value} 60 | 61 | 62 | 63 | ); 64 | }; 65 | 66 | export const MultiplePortals: Story = () => ( 67 | <> 68 | 69 | 70 | I'm a box inside a portal! 71 | 72 | 73 | 74 | 75 | I'm a box inside a portal! 76 | 77 | 78 | 79 | ); 80 | -------------------------------------------------------------------------------- /src/components/Portal/Portal.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import * as ReactDOM from 'react-dom'; 3 | import { ChildrenProp } from '../../types'; 4 | 5 | export interface PortalProps extends ChildrenProp {} 6 | 7 | export const Portal: React.FC = ({ children }) => { 8 | const [ready, setReady] = React.useState(false); 9 | 10 | const container = React.useRef(); 11 | 12 | React.useEffect(() => { 13 | if (!container.current) { 14 | const el = document.createElement('div'); 15 | el.setAttribute('data-spicy-portal', ''); 16 | container.current = el; 17 | } 18 | 19 | document.body.appendChild(container.current); 20 | setReady(true); 21 | 22 | return () => { 23 | if (container.current) { 24 | document.body.removeChild(container.current); 25 | container.current = undefined; 26 | setReady(false); 27 | } 28 | }; 29 | }, []); 30 | 31 | if (ready && container.current) { 32 | return ReactDOM.createPortal(children, container.current); 33 | } 34 | 35 | return null; 36 | }; 37 | 38 | Portal.displayName = 'Portal'; 39 | -------------------------------------------------------------------------------- /src/components/Portal/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Portal'; 2 | -------------------------------------------------------------------------------- /src/components/Progress/Circular.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import styled from 'styled-components'; 3 | import { sxMixin, useComponentStyles } from '../../system'; 4 | import { AsProp, ChildrenProp, HTMLAttributes } from '../../types'; 5 | import { Box } from '../Box'; 6 | 7 | const Svg = styled.svg(sxMixin); 8 | 9 | const Circle = styled.circle(sxMixin); 10 | 11 | export interface CircularProgressProps extends HTMLAttributes, AsProp, ChildrenProp { 12 | angle?: number; 13 | color?: string; 14 | isCapRound?: boolean; 15 | isIndeterminate?: boolean; 16 | max?: number; 17 | min?: number; 18 | size?: string; 19 | thickness?: number; 20 | trackColor?: string; 21 | value?: number; 22 | } 23 | 24 | export const CircularProgress = React.forwardRef((props, ref) => { 25 | const { 26 | children, 27 | angle = 0, 28 | color = 'blue.500', 29 | isCapRound = false, 30 | isIndeterminate = false, 31 | max = 100, 32 | min = 0, 33 | trackColor = 'gray.100', 34 | thickness = 1, 35 | value = 0, 36 | ...rest 37 | } = props; 38 | 39 | const rootStyles = useComponentStyles('ProgressCircular', props); 40 | const svgStyles = useComponentStyles('ProgressCircularSvg', props); 41 | const shapeStyles = useComponentStyles('ProgressCircularShape', props); 42 | const innerStyles = useComponentStyles('ProgressCircularInner', props); 43 | 44 | const percent = Math.min(Math.max(((value - min) * 100) / (max - min), min), max) / 100; 45 | 46 | return ( 47 | 48 | 49 | 58 | 70 | {isIndeterminate && ( 71 | <> 72 | 78 | 79 | 87 | 88 | )} 89 | 90 | 91 | {children && {children}} 92 | 93 | ); 94 | }); 95 | 96 | CircularProgress.defaultProps = { 97 | size: '48px', 98 | }; 99 | 100 | CircularProgress.displayName = 'CircularProgress'; 101 | -------------------------------------------------------------------------------- /src/components/Progress/Horizontal.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { useComponentStyles } from '../../system'; 3 | import { AsProp, ChildrenProp, HTMLAttributes } from '../../types'; 4 | import { Box } from '../Box'; 5 | import { ProgressAnimation, progressKeyframe } from './styled'; 6 | 7 | export interface HorizontalProgressProps extends HTMLAttributes, AsProp, ChildrenProp { 8 | color?: string; 9 | isCapRound?: boolean; 10 | isIndeterminate?: boolean; 11 | max?: number; 12 | min?: number; 13 | trackColor?: string; 14 | value?: number; 15 | } 16 | 17 | export const HorizontalProgress = React.forwardRef((props, ref) => { 18 | const { children, isIndeterminate = false, max = 100, min = 0, trackColor = 'gray.100', value = 0, ...rest } = props; 19 | 20 | const rootStyles = useComponentStyles('ProgressHorizontal', props); 21 | const indeterminateInnerStyles = useComponentStyles('ProgressHorizontalIndeterminateInner', props); 22 | const innerStyles = useComponentStyles('ProgressHorizontalInner', props); 23 | 24 | return ( 25 | 26 | {isIndeterminate ? ( 27 | <> 28 | 29 | 30 | 31 | ) : ( 32 | 33 | {children} 34 | 35 | )} 36 | 37 | ); 38 | }); 39 | 40 | HorizontalProgress.defaultProps = { 41 | color: 'blue.500', 42 | }; 43 | 44 | HorizontalProgress.displayName = 'HorizontalProgress'; 45 | -------------------------------------------------------------------------------- /src/components/Progress/Progress.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Progress, ProgressProps, Text } from '..'; 4 | 5 | export default { 6 | title: 'Progress', 7 | component: Progress, 8 | } as Meta; 9 | 10 | export const Horizontal: Story = (props) => ; 11 | Horizontal.args = { 12 | value: 43, 13 | }; 14 | 15 | export const WithHorizontalInner: Story = (props) => { 16 | const { value = 0, min = 0, max = 100 } = props; 17 | const score = ((value - min) * 100) / (max - min); 18 | 19 | return ( 20 | 21 | 22 | {score}% 23 | 24 | 25 | ); 26 | }; 27 | WithHorizontalInner.args = { 28 | value: 43, 29 | }; 30 | 31 | export const Circular: Story = (props) => ; 32 | Circular.args = { 33 | isCircular: true, 34 | value: 43, 35 | }; 36 | 37 | export const WithCircularInner: Story = (props) => { 38 | const { value = 0, min = 0, max = 100 } = props; 39 | const score = ((value - min) * 100) / (max - min); 40 | 41 | return ( 42 | 43 | 44 | {score}% 45 | 46 | 47 | ); 48 | }; 49 | WithCircularInner.args = { isCircular: true, value: 43 }; 50 | -------------------------------------------------------------------------------- /src/components/Progress/Progress.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { CircularProgress, CircularProgressProps } from './Circular'; 3 | import { HorizontalProgress, HorizontalProgressProps } from './Horizontal'; 4 | 5 | export type ProgressProps = 6 | | ({ isCircular: true } & CircularProgressProps) 7 | | ({ isCircular: false } & HorizontalProgressProps); 8 | 9 | export const Progress = React.forwardRef(({ isCircular = false, ...rest }, ref) => 10 | isCircular ? : , 11 | ); 12 | 13 | Progress.displayName = 'Progress'; 14 | -------------------------------------------------------------------------------- /src/components/Progress/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Progress'; 2 | -------------------------------------------------------------------------------- /src/components/Progress/styled.tsx: -------------------------------------------------------------------------------- 1 | import styled, { keyframes } from 'styled-components'; 2 | 3 | export const progressKeyframe = keyframes` 4 | 0% { 5 | margin-left: 0; 6 | margin-right: 100%; 7 | } 8 | 9 | 50% { 10 | margin-left: 25%; 11 | margin-right: 0; 12 | } 13 | 14 | 100% { 15 | margin-left: 100%; 16 | margin-right: 0%; 17 | } 18 | `; 19 | 20 | export const ProgressAnimation = styled.div` 21 | /* ${progressKeyframe} */ 22 | 23 | display: none; 24 | `; 25 | -------------------------------------------------------------------------------- /src/components/Radio/Radio.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { uid } from 'react-uid'; 4 | import { Radio, RadioProps, Stack, Text } from '..'; 5 | 6 | const radioColors = [ 7 | 'blueGray', 8 | 'coolGray', 9 | 'gray', 10 | 'trueGray', 11 | 'warmGray', 12 | 'red', 13 | 'orange', 14 | 'amber', 15 | 'yellow', 16 | 'lime', 17 | 'green', 18 | 'emerald', 19 | 'teal', 20 | 'cyan', 21 | 'lightBlue', 22 | 'blue', 23 | 'indigo', 24 | 'violet', 25 | 'purple', 26 | 'fuchsia', 27 | 'pink', 28 | 'rose', 29 | 'whiteAlpha', 30 | 'blackAlpha', 31 | ]; 32 | 33 | export default { 34 | title: 'Radio', 35 | component: Radio, 36 | } as Meta; 37 | 38 | export const Usage: Story = (props) => { 39 | const [isChecked, setIsChecked] = React.useState(false); 40 | 41 | return setIsChecked(Boolean(target.checked))} />; 42 | }; 43 | Usage.args = { 44 | label: 'Radio', 45 | }; 46 | 47 | export const Group: Story = () => { 48 | const options = [ 49 | { label: 'Option 1', value: 'opt1' }, 50 | { label: 'Option 2', value: 'opt2' }, 51 | { label: 'Option 3', value: 'opt3' }, 52 | { label: 'Option 4', value: 'opt4' }, 53 | ]; 54 | 55 | const [selected, setSelected] = React.useState(null); 56 | 57 | return ( 58 | <> 59 | 60 | {options.map((option, index) => ( 61 | setSelected(target.value)} 67 | /> 68 | ))} 69 | 70 | 71 | Selected: {selected} 72 | 73 | 74 | ); 75 | }; 76 | 77 | export const Colors: Story = () => ( 78 | 79 | {radioColors.map((color, idx) => ( 80 | 81 | ))} 82 | 83 | ); 84 | 85 | export const Sizes: Story = () => ( 86 | 87 | 88 | 89 | 90 | 91 | 92 | ); 93 | -------------------------------------------------------------------------------- /src/components/Radio/Radio.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { useComponentStyles } from '../../system'; 3 | import { ColorScales } from '../../theme'; 4 | import { LiteralUnion } from '../../types'; 5 | import { Box } from '../Box'; 6 | import { Text } from '../Text'; 7 | 8 | export type RadioColors = ColorScales; 9 | 10 | export type RadioSizes = 'xs' | 'sm' | 'md' | 'lg'; 11 | 12 | export interface RadioProps extends Omit, 'width' | 'height' | 'size'> { 13 | /** Radio label. */ 14 | label?: string; 15 | /** If `true`, the radio will be disabled. */ 16 | isDisabled?: boolean; 17 | /** If `true`, the radio will be marked as invalid. */ 18 | isInvalid?: boolean; 19 | /** Color of the radio. */ 20 | color?: LiteralUnion; 21 | /** Size of the checkbox. */ 22 | size?: LiteralUnion; 23 | } 24 | 25 | export const Radio = React.forwardRef((props, ref) => { 26 | const { id, name, value, label, checked, isDisabled, isInvalid, color, size, ...rest } = props; 27 | 28 | const outerStyles = useComponentStyles('RadioOuter', props); 29 | const inputStyles = useComponentStyles('RadioInput', props); 30 | const labelStyles = useComponentStyles('RadioLabel', props); 31 | 32 | return ( 33 | 34 | 47 | {label && ( 48 | 49 | {label} 50 | 51 | )} 52 | 53 | ); 54 | }); 55 | 56 | Radio.defaultProps = { 57 | color: 'blue', 58 | size: 'md', 59 | }; 60 | 61 | Radio.displayName = 'Radio'; 62 | -------------------------------------------------------------------------------- /src/components/Radio/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Radio'; 2 | -------------------------------------------------------------------------------- /src/components/Select/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Select'; 2 | -------------------------------------------------------------------------------- /src/components/Select/util.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * util for async searchable story 3 | * this is not published in package 4 | */ 5 | 6 | import * as React from 'react'; 7 | 8 | function useSafeDispatch(dispatch: React.Dispatch) { 9 | const mounted = React.useRef(false); 10 | 11 | React.useLayoutEffect(() => { 12 | mounted.current = true; 13 | 14 | return () => { 15 | mounted.current = false; 16 | }; 17 | }, []); 18 | 19 | return React.useCallback( 20 | (arg: T) => { 21 | return mounted.current ? dispatch(arg) : undefined; 22 | }, 23 | [dispatch], 24 | ); 25 | } 26 | 27 | interface AsyncState { 28 | status?: 'idle' | 'pending' | 'rejected' | 'resolved'; 29 | data?: Data; 30 | error?: Error; 31 | } 32 | 33 | const defaultInitialState: AsyncState = { status: 'idle', data: undefined, error: undefined }; 34 | 35 | export function useAsync(initialState?: AsyncState) { 36 | const initialStateRef = React.useRef>({ 37 | ...defaultInitialState, 38 | ...initialState, 39 | }); 40 | 41 | const [{ status, data, error }, setState] = React.useReducer( 42 | (s: AsyncState, a: AsyncState) => ({ ...s, ...a }), 43 | initialStateRef.current, 44 | ); 45 | 46 | const safeSetState = useSafeDispatch>(setState); 47 | 48 | const setData = React.useCallback( 49 | (nextData?: Data) => { 50 | safeSetState({ data: nextData, status: 'resolved' }); 51 | }, 52 | [safeSetState], 53 | ); 54 | 55 | const setError = React.useCallback( 56 | (nextError: Error) => { 57 | safeSetState({ error: nextError, status: 'rejected' }); 58 | }, 59 | [safeSetState], 60 | ); 61 | 62 | const reset = React.useCallback(() => { 63 | safeSetState(initialStateRef.current); 64 | }, [safeSetState]); 65 | 66 | const run = React.useCallback( 67 | (promise: Promise) => { 68 | if (!promise || !promise.then) { 69 | throw new Error( 70 | `The argument passed to 'useAsync().run' must be a promise. Maybe a function that's passed isn't returning anything?`, 71 | ); 72 | } 73 | 74 | safeSetState({ status: 'pending' }); 75 | 76 | return promise.then( 77 | (nextData) => { 78 | setData(nextData); 79 | return nextData; 80 | }, 81 | (nextError) => { 82 | setError(nextError); 83 | return Promise.reject(nextError); 84 | }, 85 | ); 86 | }, 87 | [safeSetState, setData, setError], 88 | ); 89 | 90 | return { 91 | isIdle: status === 'idle', 92 | isLoading: status === 'pending', 93 | isError: status === 'rejected', 94 | isSuccess: status === 'resolved', 95 | 96 | setData, 97 | setError, 98 | error, 99 | status, 100 | data, 101 | run, 102 | reset, 103 | }; 104 | } 105 | -------------------------------------------------------------------------------- /src/components/Skeleton/Skeleton.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Skeleton, SkeletonProps } from '..'; 4 | 5 | export default { 6 | title: 'Skeleton', 7 | component: Skeleton, 8 | } as Meta; 9 | 10 | export const Usage: Story = (props) => ; 11 | 12 | export const Variants: Story = () => ( 13 | <> 14 | 15 | 16 | 17 | 18 | ); 19 | -------------------------------------------------------------------------------- /src/components/Skeleton/Skeleton.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { useComponentStyles } from '../../system'; 3 | import { LiteralUnion } from '../../types'; 4 | import { Box, BoxProps } from '../Box'; 5 | 6 | export type SkeletonVariants = 'text' | 'circle' | 'square'; 7 | 8 | export interface SkeletonProps extends BoxProps { 9 | /** Variant style of the skeleton. */ 10 | variant?: LiteralUnion; 11 | } 12 | 13 | export const Skeleton = React.forwardRef((props, ref) => { 14 | const { children, sx, ...rest } = props; 15 | 16 | const styles = useComponentStyles('Skeleton', props); 17 | 18 | return ( 19 | 20 | {children} 21 | 22 | ); 23 | }); 24 | 25 | Skeleton.defaultProps = { 26 | variant: 'text', 27 | }; 28 | 29 | Skeleton.displayName = 'Skeleton'; 30 | -------------------------------------------------------------------------------- /src/components/Skeleton/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Skeleton'; 2 | -------------------------------------------------------------------------------- /src/components/Spinner/Spinner.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Spinner, SpinnerProps } from '..'; 4 | 5 | export default { 6 | title: 'Spinner', 7 | component: Spinner, 8 | } as Meta; 9 | 10 | export const Usage: Story = (props) => ; 11 | -------------------------------------------------------------------------------- /src/components/Spinner/Spinner.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SxProp, useComponentStyles } from '../../system'; 3 | import { AsProp, HTMLAttributes, LiteralUnion } from '../../types'; 4 | import { Box } from '../Box'; 5 | 6 | export type SpinnerSizes = 'xs' | 'sm' | 'md' | 'lg' | 'xl'; 7 | 8 | export interface SpinnerProps extends HTMLAttributes, AsProp, SxProp { 9 | /** Color of the spinner. */ 10 | color?: string; 11 | /** Color of the spinner's track. */ 12 | trackColor?: string; 13 | /** Thickness of the spinner. */ 14 | thickness?: string; 15 | /** Spinner animation speed. */ 16 | speed?: string; 17 | /** Spinner size. */ 18 | size?: LiteralUnion; 19 | } 20 | 21 | export const Spinner = React.forwardRef((props, ref) => { 22 | const { sx, color, trackColor, thickness, speed, size, ...rest } = props; 23 | 24 | const styles = useComponentStyles('Spinner', props); 25 | 26 | return ; 27 | }); 28 | 29 | Spinner.defaultProps = { 30 | color: 'blue.500', 31 | trackColor: 'transparent', 32 | thickness: '2px', 33 | speed: '0.45s', 34 | size: 'md', 35 | }; 36 | 37 | Spinner.displayName = 'Spinner'; 38 | -------------------------------------------------------------------------------- /src/components/Spinner/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Spinner'; 2 | -------------------------------------------------------------------------------- /src/components/Stack/Stack.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Box, Stack, StackProps } from '..'; 4 | 5 | export default { 6 | title: 'Stack', 7 | component: Stack, 8 | } as Meta; 9 | 10 | export const Usage: Story = (props) => ( 11 | 12 | 13 | Box 1 14 | 15 | 16 | Box 2 17 | 18 | 19 | Box 3 20 | 21 | 22 | ); 23 | Usage.args = { 24 | spacing: 4, 25 | }; 26 | 27 | export const Responsive: Story = () => ( 28 | 29 | 30 | Box 1 31 | 32 | 33 | Box 2 34 | 35 | 36 | Box 3 37 | 38 | 39 | ); 40 | 41 | export const WithDividers: Story = () => ( 42 | } spacing={4}> 43 | 44 | Box 1 45 | 46 | 47 | Box 2 48 | 49 | 50 | Box 3 51 | 52 | 53 | ); 54 | 55 | export const WrappedChildren: Story = () => ( 56 | 57 | <>line 1 58 | <>line 2 59 | <>line 3 60 | 61 | ); 62 | -------------------------------------------------------------------------------- /src/components/Stack/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Stack'; 2 | -------------------------------------------------------------------------------- /src/components/Switch/Switch.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { uid } from 'react-uid'; 4 | import { Switch, SwitchProps, Stack } from '..'; 5 | 6 | const switchColors = [ 7 | 'blueGray', 8 | 'coolGray', 9 | 'gray', 10 | 'trueGray', 11 | 'warmGray', 12 | 'red', 13 | 'orange', 14 | 'amber', 15 | 'yellow', 16 | 'lime', 17 | 'green', 18 | 'emerald', 19 | 'teal', 20 | 'cyan', 21 | 'lightBlue', 22 | 'blue', 23 | 'indigo', 24 | 'violet', 25 | 'purple', 26 | 'fuchsia', 27 | 'pink', 28 | 'rose', 29 | 'whiteAlpha', 30 | 'blackAlpha', 31 | ]; 32 | 33 | export default { 34 | title: 'Switch', 35 | component: Switch, 36 | } as Meta; 37 | 38 | export const Usage: Story = (props) => { 39 | const [isChecked, setIsChecked] = React.useState(false); 40 | 41 | return setIsChecked(Boolean(target.checked))} />; 42 | }; 43 | 44 | export const Colors: Story = () => ( 45 | 46 | {switchColors.map((color, idx) => ( 47 | 48 | ))} 49 | 50 | ); 51 | 52 | export const Sizes: Story = () => ( 53 | 54 | 55 | 56 | 57 | 58 | ); 59 | -------------------------------------------------------------------------------- /src/components/Switch/Switch.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { useComponentStyles } from '../../system'; 3 | import { ColorScales } from '../../theme'; 4 | import { LiteralUnion } from '../../types'; 5 | import { Box } from '../Box'; 6 | 7 | export type SwitchColors = ColorScales; 8 | 9 | export type SwitchSizes = 'xs' | 'sm' | 'md' | 'lg'; 10 | 11 | export interface SwitchProps extends Omit, 'width' | 'height' | 'size'> { 12 | label?: string; 13 | isDisabled?: boolean; 14 | isInvalid?: boolean; 15 | color?: LiteralUnion; 16 | size?: LiteralUnion; 17 | } 18 | 19 | export const Switch = React.forwardRef((props, ref) => { 20 | const { id, name, value, label, checked, isDisabled, isInvalid, color, size, ...rest } = props; 21 | 22 | const outerStyles = useComponentStyles('SwitchOuter', props); 23 | const inputStyles = useComponentStyles('SwitchInput', props); 24 | const toggleStyles = useComponentStyles('SwitchToggle', props); 25 | 26 | return ( 27 | 28 | 42 | 43 | 44 | ); 45 | }); 46 | 47 | Switch.defaultProps = { 48 | color: 'blue', 49 | size: 'md', 50 | }; 51 | 52 | Switch.displayName = 'Switch'; 53 | -------------------------------------------------------------------------------- /src/components/Switch/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Switch'; 2 | -------------------------------------------------------------------------------- /src/components/Tabs/Tab.tsx: -------------------------------------------------------------------------------- 1 | import { sfp } from '@spicy-ui/styled-system'; 2 | import * as React from 'react'; 3 | import styled from 'styled-components'; 4 | import { componentStylesMixin, sxMixin, SxProp } from '../../system'; 5 | import { AsProp, ChildrenProp, HTMLAttributes } from '../../types'; 6 | 7 | /** Don't pass the 'type' prop when the tab is not a button component. */ 8 | const tabSfp = (prop: string, _fn: any, target: any): boolean => { 9 | if (target === 'button') { 10 | return sfp(['isDisabled', 'isSelected'])(prop); 11 | } 12 | 13 | return sfp(['type', 'isDisabled', 'isSelected'])(prop); 14 | }; 15 | 16 | export interface TabProps extends HTMLAttributes, AsProp, ChildrenProp, SxProp { 17 | isDisabled?: boolean; 18 | isSelected?: boolean; 19 | } 20 | 21 | export const Tab = styled.button 22 | .attrs(({ isDisabled, isSelected, onClick }) => ({ 23 | 'aria-disabled': isDisabled || undefined, 24 | 'data-disabled': isDisabled || undefined, 25 | 'aria-selected': isSelected || undefined, 26 | 'data-selected': isSelected || undefined, 27 | disabled: isDisabled || undefined, 28 | onClick: (e: React.MouseEvent) => { 29 | if (isDisabled) { 30 | e.preventDefault(); 31 | return; 32 | } 33 | 34 | if (onClick) { 35 | onClick(e); 36 | } 37 | }, 38 | tabIndex: isDisabled ? -1 : undefined, 39 | })) 40 | .withConfig({ 41 | shouldForwardProp: tabSfp as any, 42 | })(componentStylesMixin('Tab'), sxMixin); 43 | 44 | Tab.defaultProps = { 45 | type: 'button', 46 | role: 'tab', 47 | }; 48 | 49 | Tab.displayName = 'Tab'; 50 | -------------------------------------------------------------------------------- /src/components/Tabs/Tabs.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { Link, matchPath, MemoryRouter, Redirect, Route, useLocation } from 'react-router-dom'; 4 | import { uid } from 'react-uid'; 5 | import { Badge, Stack, Tab, Tabs, TabsProps } from '..'; 6 | 7 | export default { 8 | title: 'Tabs', 9 | component: Tabs, 10 | subcomponents: { Tab }, 11 | } as Meta; 12 | 13 | export const Usage: Story = (props) => { 14 | const [tabIndex, setTabIndex] = React.useState(0); 15 | 16 | const tabs = Array(3) 17 | .fill('Tab') 18 | .map((label, i) => ( 19 | setTabIndex(i)}> 20 | {label} {i} 21 | 22 | )); 23 | 24 | return ( 25 | <> 26 | {tabs} 27 |
{tabIndex}
28 | 29 | ); 30 | }; 31 | 32 | export const Variants: Story = (props) => { 33 | const [tabIndex, setTabIndex] = React.useState(0); 34 | 35 | const tabs = Array(3) 36 | .fill('Tab') 37 | .map((label, i) => ( 38 | setTabIndex(i)}> 39 | {label} {i} 40 | 41 | )); 42 | 43 | return ( 44 | 45 | 46 | {tabs} 47 | 48 | 49 | {tabs} 50 | 51 | 52 | {tabs} 53 | 54 | 55 | ); 56 | }; 57 | export const Disabled: Story = (props) => { 58 | const [tabIndex, setTabIndex] = React.useState(0); 59 | 60 | const tabs = Array(3) 61 | .fill('Tab') 62 | .map((label, i) => ( 63 | setTabIndex(i)}> 64 | {label} {i} 65 | 66 | )); 67 | 68 | return ( 69 | <> 70 | {tabs} 71 |
{tabIndex}
72 | 73 | ); 74 | }; 75 | 76 | const RouteAwareTabs: React.FC = (props) => { 77 | const { pathname } = useLocation(); 78 | const isSelected = React.useCallback((path: string) => !!matchPath(pathname, { path }), [pathname]); 79 | 80 | return ( 81 | 82 | 83 | Overview 84 | 85 | 86 | Sales 87 | 6 88 | 89 | 90 | Settings 91 | 92 | 93 | ); 94 | }; 95 | 96 | export const WithReactRouter: Story = (props) => ( 97 | 98 | 99 | 100 |
101 |
overview
} /> 102 |
sales
} /> 103 |
settings
} /> 104 | 105 | {/* Fallback default route */} 106 | } /> 107 |
108 |
109 | ); 110 | -------------------------------------------------------------------------------- /src/components/Tabs/Tabs.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SxProp, useComponentStyles } from '../../system'; 3 | import { ColorScales } from '../../theme'; 4 | import { AsProp, ChildrenProp, HTMLAttributes, LiteralUnion } from '../../types'; 5 | import { Box } from '../Box'; 6 | 7 | export type TabColors = ColorScales; 8 | 9 | export type TabVariants = 'line' | 'enclosed' | 'pill'; 10 | 11 | export interface TabsProps extends HTMLAttributes, AsProp, ChildrenProp, SxProp { 12 | color?: LiteralUnion; 13 | variant?: LiteralUnion; 14 | } 15 | 16 | export const Tabs = React.forwardRef((props, ref) => { 17 | const { children, sx, ...rest } = props; 18 | 19 | const styles = useComponentStyles('Tabs', props); 20 | 21 | return ( 22 | 23 | {children} 24 | 25 | ); 26 | }); 27 | 28 | Tabs.defaultProps = { 29 | color: 'blue', 30 | variant: 'line', 31 | }; 32 | 33 | Tabs.displayName = 'Tabs'; 34 | -------------------------------------------------------------------------------- /src/components/Tabs/index.tsx: -------------------------------------------------------------------------------- 1 | export * from './Tab'; 2 | export * from './Tabs'; 3 | -------------------------------------------------------------------------------- /src/components/Tag/Tag.stories.tsx: -------------------------------------------------------------------------------- 1 | import { action } from '@storybook/addon-actions'; 2 | import { Meta, Story } from '@storybook/react'; 3 | import * as React from 'react'; 4 | import { HiOutlineArchive, HiOutlinePaperAirplane, HiPlus } from 'react-icons/hi'; 5 | import { Box, Stack, Tag, TagAction, TagIconAfter, TagIconBefore, TagLabel, TagProps } from '..'; 6 | 7 | export default { 8 | title: 'Tag', 9 | component: Tag, 10 | } as Meta; 11 | 12 | export const Usage: Story = (props) => Sample Tag; 13 | 14 | export const TextOverflow: Story = (props) => ( 15 | 16 | 17 | This tag will overflow 18 | 19 | 20 | ); 21 | 22 | export const Sizes: Story = (props) => ( 23 | 24 | {['sm', 'md', 'lg'].map((size) => ( 25 | 26 | Fuchsia 27 | 28 | ))} 29 | 30 | ); 31 | Sizes.args = { 32 | color: 'fuchsia', 33 | variant: 'solid', 34 | }; 35 | 36 | export const WithIconBefore: Story = (props) => ( 37 | 38 | {['sm', 'md', 'lg'].map((size) => ( 39 | 40 | } /> 41 | Red 42 | 43 | ))} 44 | 45 | ); 46 | WithIconBefore.args = { 47 | color: 'red', 48 | }; 49 | 50 | export const WithIconAfter: Story = (props) => ( 51 | 52 | {['sm', 'md', 'lg'].map((size) => ( 53 | 54 | Blue 55 | } /> 56 | 57 | ))} 58 | 59 | ); 60 | WithIconAfter.args = { 61 | color: 'blue', 62 | variant: 'outline', 63 | }; 64 | 65 | export const WithAction: Story = (props) => ( 66 | 67 | {['sm', 'md', 'lg'].map((size) => ( 68 | 69 | Emerald 70 | 71 | 72 | ))} 73 | 74 | ); 75 | WithAction.args = { 76 | isRound: true, 77 | color: 'emerald', 78 | variant: 'solid', 79 | }; 80 | 81 | export const WithCustomActionIcon: Story = (props) => ( 82 | 83 | {['sm', 'md', 'lg'].map((size) => ( 84 | 85 | Yellow 86 | } onClick={action('tag')} /> 87 | 88 | ))} 89 | 90 | ); 91 | WithCustomActionIcon.args = { 92 | color: 'yellow', 93 | }; 94 | -------------------------------------------------------------------------------- /src/components/Tag/Tag.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SxProp, useComponentStyles } from '../../system'; 3 | import { ColorScales } from '../../theme'; 4 | import { AsProp, ChildrenProp, HTMLAttributes, LiteralUnion } from '../../types'; 5 | import { Box } from '../Box'; 6 | 7 | export type TagColors = ColorScales; 8 | 9 | export type TagSizes = 'sm' | 'md' | 'lg'; 10 | 11 | export type TagVariants = 'outline' | 'solid' | 'subtle'; 12 | 13 | export interface TagProps extends HTMLAttributes, AsProp, ChildrenProp, SxProp { 14 | /** Label shown within the tag. */ 15 | label?: React.ReactNode; 16 | /** If `true`, the tag will be rounded. */ 17 | isRound?: boolean; 18 | /** Color of the tag. */ 19 | color?: LiteralUnion; 20 | /** Size of the tag. */ 21 | size?: LiteralUnion; 22 | /** Variant of the tag. */ 23 | variant?: LiteralUnion; 24 | } 25 | 26 | export const Tag = React.forwardRef((props, ref) => { 27 | const { as, children, sx, label, isRound, color, size, variant, ...rest } = props; 28 | 29 | const styles = useComponentStyles('Tag', props); 30 | 31 | return ( 32 | 33 | {label || children} 34 | 35 | ); 36 | }); 37 | 38 | Tag.defaultProps = { 39 | color: 'gray', 40 | size: 'md', 41 | variant: 'subtle', 42 | }; 43 | 44 | Tag.displayName = 'Tag'; 45 | -------------------------------------------------------------------------------- /src/components/Tag/TagAction.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { HiX } from 'react-icons/hi'; 3 | import { useComponentStyles } from '../../system'; 4 | import { IconButton, IconButtonProps } from '../Button'; 5 | 6 | export interface TagActionProps extends Omit {} 7 | 8 | export const TagAction = React.forwardRef((props, ref) => { 9 | const { children = , sx, ...rest } = props; 10 | 11 | const styles = useComponentStyles('TagAction', props); 12 | 13 | return ( 14 | 15 | {children} 16 | 17 | ); 18 | }); 19 | 20 | TagAction.displayName = 'TagAction'; 21 | -------------------------------------------------------------------------------- /src/components/Tag/TagIcon.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SxProp, useComponentStyles } from '../../system'; 3 | import { ChildrenProp, HTMLAttributes } from '../../types'; 4 | import { Box } from '../Box'; 5 | 6 | export interface TagIconProps extends HTMLAttributes, ChildrenProp, SxProp { 7 | icon?: React.ReactNode; 8 | } 9 | 10 | const TagIcon = React.forwardRef((props, ref) => { 11 | const { children, icon, ...rest } = props; 12 | 13 | return ( 14 | 15 | {icon || children} 16 | 17 | ); 18 | }); 19 | 20 | TagIcon.displayName = 'TagIcon'; 21 | 22 | export const TagIconBefore = React.forwardRef((props, ref) => { 23 | const { sx, ...rest } = props; 24 | 25 | const styles = useComponentStyles('TagIconBefore', props); 26 | 27 | return ; 28 | }); 29 | 30 | TagIconBefore.displayName = 'TagIconBefore'; 31 | 32 | export const TagIconAfter = React.forwardRef((props, ref) => { 33 | const { sx, ...rest } = props; 34 | 35 | const styles = useComponentStyles('TagIconAfter', props); 36 | 37 | return ; 38 | }); 39 | 40 | TagIconAfter.displayName = 'TagIconAfter'; 41 | -------------------------------------------------------------------------------- /src/components/Tag/TagLabel.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SxProp, useComponentStyles } from '../../system'; 3 | import { AsProp, ChildrenProp, HTMLAttributes } from '../../types'; 4 | import { Box } from '../Box'; 5 | 6 | export interface TagLabelProps extends HTMLAttributes, AsProp, ChildrenProp, SxProp { 7 | label?: React.ReactNode; 8 | } 9 | 10 | export const TagLabel = React.forwardRef((props, ref) => { 11 | const { children, sx, label, ...rest } = props; 12 | 13 | const styles = useComponentStyles('TagLabel', props); 14 | 15 | return ( 16 | 17 | {label || children} 18 | 19 | ); 20 | }); 21 | 22 | TagLabel.displayName = 'TagLabel'; 23 | -------------------------------------------------------------------------------- /src/components/Tag/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Tag'; 2 | export * from './TagAction'; 3 | export * from './TagIcon'; 4 | export * from './TagLabel'; 5 | -------------------------------------------------------------------------------- /src/components/Text/Text.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Meta, Story } from '@storybook/react'; 2 | import * as React from 'react'; 3 | import { uid } from 'react-uid'; 4 | import { Stack, Text, TextProps, TextVariant } from '..'; 5 | 6 | const textVariants: TextVariant[] = [ 7 | 'xs', 8 | 'sm', 9 | 'md', 10 | 'lg', 11 | 'xl', 12 | '2xl', 13 | '3xl', 14 | '4xl', 15 | '5xl', 16 | '6xl', 17 | '7xl', 18 | '8xl', 19 | '9xl', 20 | 'inherit', 21 | ]; 22 | 23 | export default { 24 | title: 'Text', 25 | component: Text, 26 | } as Meta; 27 | 28 | export const Usage: Story = (props) => The quick brown fox jumped over the lazy dog.; 29 | 30 | export const Variants: Story = () => ( 31 | 32 | {textVariants.map((variant, idx) => ( 33 | 34 | {variant}: The quick brown fox jumped over the lazy dog. 35 | 36 | ))} 37 | 38 | ); 39 | 40 | export const SemanticText: Story = () => ( 41 | 42 | {[ 43 | { as: 'a', label: 'Link' }, 44 | { as: 'em', label: 'Emphasis' }, 45 | { as: 'strong', label: 'Strong' }, 46 | { as: 'small', label: 'Small' }, 47 | { as: 'code', label: '
hello world
' }, 48 | { as: 'abbr', label: 'I18N' }, 49 | { as: 'cite', label: 'Citation' }, 50 | { as: 'del', label: 'Deleted' }, 51 | { as: 'ins', label: 'Inserted' }, 52 | { as: 'kbd', label: 'Ctrl + C' }, 53 | { as: 'mark', label: 'Highlighted' }, 54 | { as: 's', label: 'Strikethrough' }, 55 | { as: 'samp', label: 'Sample' }, 56 | { as: 'sub', label: 'sub' }, 57 | { as: 'sup', label: 'sup' }, 58 | ].map(({ as, label }, idx) => ( 59 | 60 | {label} 61 | 62 | ))} 63 |
64 | ); 65 | -------------------------------------------------------------------------------- /src/components/Text/Text.tsx: -------------------------------------------------------------------------------- 1 | import { shouldForwardProp } from '@spicy-ui/styled-system'; 2 | import styled from 'styled-components'; 3 | import { allSystem, AllSystemProps, componentStylesMixin, sxMixin, SxProp } from '../../system'; 4 | import { AsProp, ChildrenProp, HTMLAttributes, LiteralUnion } from '../../types'; 5 | 6 | export type TextVariant = 7 | | 'xs' 8 | | 'sm' 9 | | 'md' 10 | | 'lg' 11 | | 'xl' 12 | | '2xl' 13 | | '3xl' 14 | | '4xl' 15 | | '5xl' 16 | | '6xl' 17 | | '7xl' 18 | | '8xl' 19 | | '9xl' 20 | | 'inherit'; 21 | 22 | export interface TextProps extends HTMLAttributes, AsProp, ChildrenProp, AllSystemProps, SxProp { 23 | color?: string; 24 | /** Variant of the text. */ 25 | variant?: LiteralUnion; 26 | } 27 | 28 | export const Text = styled.p.withConfig({ shouldForwardProp })( 29 | componentStylesMixin('Text'), 30 | sxMixin, 31 | allSystem, 32 | ); 33 | 34 | Text.defaultProps = { 35 | variant: 'md', 36 | }; 37 | 38 | Text.displayName = 'Text'; 39 | -------------------------------------------------------------------------------- /src/components/Text/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Text'; 2 | -------------------------------------------------------------------------------- /src/components/TextArea/TextArea.stories.tsx: -------------------------------------------------------------------------------- 1 | import { action } from '@storybook/addon-actions'; 2 | import { Meta, Story } from '@storybook/react'; 3 | import * as React from 'react'; 4 | import { Stack, TextArea, TextAreaProps } from '..'; 5 | 6 | export default { 7 | title: 'TextArea', 8 | component: TextArea, 9 | } as Meta; 10 | 11 | export const Usage: Story = (props) => ( 12 |