diff --git a/.babelrc b/.babelrc index ae52d836..2c055d07 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,16 @@ { - "presets": ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"] -} \ No newline at end of file + "sourceType": "unambiguous", + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "chrome": 100 + } + } + ], + "@babel/preset-typescript", + "@babel/preset-react" + ], + "plugins": ["babel-plugin-styled-components"] +} diff --git a/.eslintrc.json b/.eslintrc.json index ebc0c4ca..a281039e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -12,29 +12,21 @@ "plugin:prettier/recommended", "plugin:react/jsx-runtime" ], - "plugins": [ - "@typescript-eslint", "react", "prettier" - ], + "plugins": ["@typescript-eslint", "react", "prettier"], "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaFeatures": { "experimentalObjectRestSpread": true, "jsx": true }, - "ecmaVersion": 2018, + "ecmaVersion": "latest", "sourceType": "module", "project": "./tsconfig.json" }, "ignorePatterns": ["*.svg", "*.ttf", "*.woff", "*.eot", "*.md"], "rules": { - "quotes": [ - "error", - "single" - ], - "semi": [ - "error", - "never" - ], + "quotes": ["error", "single"], + "semi": ["error", "never"], "prettier/prettier": [ "error", { @@ -43,21 +35,28 @@ "arrowParens": "always" } ], - "react/prop-types": ["warn"], + "react/prop-types": ["off"], "no-undef": "off", "no-unused-vars": "off", "@typescript-eslint/no-unused-vars": "off", "no-console": "warn", "import/no-unresolved": 0, - "react/jsx-filename-extension": [1, { - "extensions": [ - ".ts", - ".tsx" - ] - }], - "import/extensions": ["error", "never", {"svg": "always", "ts": "always", "tsx": "always", "json": "always"}], + "react/jsx-filename-extension": [ + 1, + { + "extensions": [".ts", ".tsx"] + } + ], + "import/extensions": [ + "error", + "never", + { "svg": "always", "ts": "always", "tsx": "always", "json": "always" } + ], "no-use-before-define": ["error", { "variables": false }], - "@typescript-eslint/no-use-before-define": ["error", { "variables": false }], + "@typescript-eslint/no-use-before-define": [ + "error", + { "variables": false } + ], "no-empty-function": "warn", "@typescript-eslint/no-empty-function": ["warn"], "dot-notation": "warn", @@ -65,6 +64,7 @@ "import/no-extraneous-dependencies": "off", "react/no-array-index-key": "off", "react/function-component-definition": "off", - "react/default-props-match-prop-types": "off" + "react/default-props-match-prop-types": "off", + "react/require-default-props": [0] } } diff --git a/.storybook/main.js b/.storybook/main.js deleted file mode 100644 index 9b7f2ad2..00000000 --- a/.storybook/main.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = { - stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], - addons: [ - '@storybook/addon-links', - '@storybook/addon-essentials', - '@storybook/addon-interactions', - ], - framework: '@storybook/react', - babel: async options => { - options.plugins.push('babel-plugin-inline-react-svg') - return options - }, -} diff --git a/.storybook/main.ts b/.storybook/main.ts new file mode 100644 index 00000000..773f1ff2 --- /dev/null +++ b/.storybook/main.ts @@ -0,0 +1,35 @@ +import type { StorybookConfig } from '@storybook/react-webpack5' +const config: StorybookConfig = { + stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(js|jsx|ts|tsx)'], + addons: [ + '@storybook/addon-links', + '@storybook/addon-essentials', + '@storybook/addon-styling', + '@storybook/addon-interactions', + '@storybook/addon-mdx-gfm', + ], + framework: { + name: '@storybook/react-webpack5', + options: {}, + }, + docs: { + autodocs: 'tag', + }, + // webpackFinal: async (config) => { + // const assetRule = config.module.rules.find(({ test }) => test.test('.svg')) + + // const assetLoader = { + // loader: assetRule.loader, + // options: assetRule.options || assetRule.query, + // } + + // // Merge our rule with existing assetLoader rules + // config.module.rules.unshift({ + // test: /\.svg$/, + // use: ['@svgr/webpack', assetLoader], + // }) + + // return config + // }, +} +export default config diff --git a/.storybook/preview.js b/.storybook/preview.js deleted file mode 100644 index 48afd568..00000000 --- a/.storybook/preview.js +++ /dev/null @@ -1,9 +0,0 @@ -export const parameters = { - actions: { argTypesRegex: "^on[A-Z].*" }, - controls: { - matchers: { - color: /(background|color)$/i, - date: /Date$/, - }, - }, -} \ No newline at end of file diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx new file mode 100644 index 00000000..6d4716e8 --- /dev/null +++ b/.storybook/preview.tsx @@ -0,0 +1,31 @@ +import React from 'react' +import type { Preview } from '@storybook/react' +import { ThemeProvider } from 'styled-components' +import theme from '../src/theme/theme' + +const preview: Preview = { + parameters: { + actions: { argTypesRegex: '^on[A-Z].*' }, + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/, + }, + }, + }, + decorators: [ + (Story) => ( + + {/* */} + + + ), + ], +} + +export default preview diff --git a/icons/tsconfig.json b/icons/tsconfig.json index c5751549..2dd701fc 100644 --- a/icons/tsconfig.json +++ b/icons/tsconfig.json @@ -6,7 +6,7 @@ "jsx": "react", "module": "ESNext", "declaration": true, - "declarationDir": "src/types/icons", + "declarationDir": "types", "sourceMap": true, "outDir": "dist", "moduleResolution": "node", @@ -15,12 +15,6 @@ "forceConsistentCasingInFileNames": true, "allowJs": true }, - "include": [ - "../src/components/icons", - "../src/types/svg.d.ts" - ], - "exclude": [ - "../dist", - "../node_modules", - ], -} \ No newline at end of file + "include": ["../src/components/icons", "../src/types/svg.d.ts"], + "exclude": ["../dist", "../node_modules"] +} diff --git a/package.json b/package.json index 62431290..930126e8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "ooni-components", + "type": "module", "version": "0.5.0-alpha.6", "main": "dist/index.js", "module": "dist/esm/index.js", @@ -9,102 +10,89 @@ "author": "Arturo Filastò ", "license": "BSD-3-Clause", "dependencies": { - "@rebass/forms": "^4.0.6", + "@styled-system/css": "^5.1.5", + "@styled-system/should-forward-prop": "^5.1.5", "react-icon-base": "^2.1.2", - "rebass": "^4.0.7", "styled-system": "^5.1.5" }, "devDependencies": { - "@babel/core": "^7.18.6", - "@babel/preset-env": "^7.18.6", + "@babel/core": "^7.21.8", + "@babel/preset-env": "^7.21.5", "@babel/preset-react": "^7.18.6", - "@babel/preset-typescript": "^7.18.6", - "@rollup/plugin-commonjs": "^22.0.1", - "@rollup/plugin-json": "^4.1.0", - "@rollup/plugin-node-resolve": "^13.3.0", - "@rollup/plugin-typescript": "^8.3.3", - "@rollup/plugin-url": "^7.0.0", - "@storybook/addon-actions": "^6.5.9", - "@storybook/addon-essentials": "^6.5.9", - "@storybook/addon-interactions": "^6.5.9", - "@storybook/addon-links": "^6.5.9", - "@storybook/builder-webpack4": "^6.5.9", - "@storybook/manager-webpack4": "^6.5.9", - "@storybook/react": "^6.5.9", - "@storybook/testing-library": "^0.0.13", - "@svgr/rollup": "^6.2.1", - "@testing-library/jest-dom": "^5.16.4", - "@testing-library/react": "^12.1.5", - "@testing-library/user-event": "^14.2.5", - "@types/jest": "^28.1.5", - "@types/react": "^17.0.43", + "@babel/preset-typescript": "^7.21.5", + "@rollup/plugin-commonjs": "^24.1.0", + "@rollup/plugin-json": "^6.0.0", + "@rollup/plugin-node-resolve": "^15.0.2", + "@rollup/plugin-terser": "^0.4.1", + "@rollup/plugin-typescript": "^11.1.0", + "@rollup/plugin-url": "^8.0.1", + "@storybook/addon-essentials": "^7.0.20", + "@storybook/addon-interactions": "^7.0.20", + "@storybook/addon-links": "^7.0.20", + "@storybook/addon-mdx-gfm": "^7.0.20", + "@storybook/blocks": "^7.0.20", + "@storybook/react": "^7.0.20", + "@storybook/react-webpack5": "^7.0.20", + "@storybook/testing-library": "^0.1.0", + "@svgr/rollup": "^7.0.0", + "@testing-library/dom": "^9.2.0", + "@testing-library/jest-dom": "^5.16.5", + "@testing-library/react": "^14.0.0", + "@testing-library/user-event": "^14.4.3", + "@types/jest": "^29.5.1", + "@types/react": "^18.2.5", "@types/react-icon-base": "^2.1.4", - "@types/rebass": "^4.0.10", - "@types/rebass__forms": "^4.0.6", - "@types/styled-components": "^5.1.25", - "@types/styled-system": "^5.1.15", - "@types/styled-system__css": "^5.0.16", - "@types/testing-library__jest-dom": "^5.14.5", - "@types/testing-library__react": "^10.2.0", - "@typescript-eslint/eslint-plugin": "^5.30.6", - "@typescript-eslint/parser": "^5.30.6", - "babel-loader": "^8.2.5", - "babel-plugin-inline-react-svg": "^2.0.1", - "cheerio": "^1.0.0-rc.2", - "eslint": "8.2.0", - "eslint-config-airbnb": "19.0.4", - "eslint-config-prettier": "^8.5.0", - "eslint-plugin-import": "2.25.3", - "eslint-plugin-jsx-a11y": "6.5.1", + "@types/styled-components": "^5.1.26", + "@types/styled-system": "^5.1.16", + "@types/styled-system__css": "^5.0.17", + "@typescript-eslint/eslint-plugin": "^5.59.2", + "@typescript-eslint/parser": "^5.59.2", + "babel-loader": "^9.1.2", + "babel-plugin-inline-react-svg": "^2.0.2", + "babel-plugin-styled-components": "^2.1.3", + "cheerio": "^1.0.0-rc.12", + "eslint": "^8.39.0", + "eslint-config-airbnb": "^19.0.4", + "eslint-config-prettier": "^8.8.0", + "eslint-plugin-import": "^2.27.5", + "eslint-plugin-jsx-a11y": "^6.7.1", "eslint-plugin-prettier": "^4.2.1", - "eslint-plugin-react": "7.28.0", - "eslint-plugin-react-hooks": "4.3.0", - "eslint-plugin-storybook": "^0.6.0", + "eslint-plugin-react": "^7.32.2", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-storybook": "^0.6.12", "eslint-watch": "^8.0.0", - "gh-pages": "^4.0.0", - "jest": "^28.1.3", - "jest-environment-jsdom": "^28.1.3", + "gh-pages": "^5.0.0", + "jest": "^29.5.0", + "jest-environment-jsdom": "^29.5.0", "jest-svg-transformer": "^1.0.0", - "prettier": "^2.7.1", - "react": "^17.0.2", - "react-dom": "^17.0.2", - "react-icons": "^4.4.0", - "react-lottie": "^1.2.3", - "rimraf": "^3.0.2", - "rollup": "^2.75.7", + "prettier": "^2.8.8", + "prop-types": "^15.8.1", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "react-icons": "^4.8.0", + "rimraf": "^5.0.0", + "rollup": "^3.21.6", "rollup-plugin-copy": "^3.4.0", - "rollup-plugin-dts": "^4.2.2", - "rollup-plugin-filesize": "^9.1.2", + "rollup-plugin-dts": "^5.3.0", + "rollup-plugin-filesize": "^10.0.0", "rollup-plugin-peer-deps-external": "^2.2.4", - "rollup-plugin-terser": "^7.0.2", - "rollup-plugin-visualizer": "^5.6.0", - "styled-components": "^5.1.1", - "ts-jest": "^28.0.6", - "typescript": "^4.7.4" + "rollup-plugin-typescript2": "^0.34.1", + "rollup-plugin-visualizer": "^5.9.0", + "storybook": "^7.0.20", + "styled-components": "^6.0.0-rc.3", + "ts-jest": "^29.1.0", + "tslib": "^2.5.0", + "typescript": "^5.0.4" }, "resolutions": { - "rebass": "4.0.7", - "styled-components": "5.1.1", - "styled-system": "5.1.5", - "acorn": "^6.4.1", - "minimist": "^1.2.2", - "serialize-javascript": "^3.1.0", - "js-yaml": "^3.13.1", - "prismjs": "^1.21.0", - "node-fetch": "^2.6.1", + "serialize-javascript": "^6.0.0", + "node-fetch": "^2.6.7", "kind-of": "^6.0.3", - "ssri": "^8.0.1", - "react-dev-utils": "^11.0.4", - "immer": "^8.0.1", - "node-notifier": "^8.0.1", - "highlight.js": "^10.4.1" + "immer": "^8.0.1" }, "peerDependencies": { - "@rebass/forms": "^4.0.6", - "react": "^17.0.2", - "react-dom": "^17.0.2", - "rebass": "^4.0.7", - "styled-components": "^5.1.1" + "react": ">= 17", + "styled-components": ">= 5" }, "scripts": { "build:clean": "rimraf dist && rimraf index.d.ts && rimraf icons/index.d.ts", @@ -118,12 +106,11 @@ "release": "yarn run build && yarn publish --new-version $npm_package_version", "release:win": "yarn run build && yarn publish --new-version %npm_package_version%", "release:alpha": "yarn publish tag --alpha", - "storybook": "start-storybook -p 6006", - "build-storybook": "build-storybook", - "deploy-storybook": "gh-pages -d storybook-static", "eslint": "esw src/**", "eslint-watch": "esw -w --changed src/**", - "eslint-watch-quiet": "esw -w --quiet --changed src/**" + "eslint-watch-quiet": "esw -w --quiet --changed src/**", + "storybook": "storybook dev -p 6006", + "build-storybook": "storybook build" }, "files": [ "dist", diff --git a/rollup.config.js b/rollup.config.js index 651a73ea..0f325eea 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,20 +3,20 @@ import commonjs from '@rollup/plugin-commonjs' import typescript from '@rollup/plugin-typescript' import dts from 'rollup-plugin-dts' import json from '@rollup/plugin-json' -import { terser } from 'rollup-plugin-terser' +import terser from '@rollup/plugin-terser' import { visualizer } from 'rollup-plugin-visualizer' import filesize from 'rollup-plugin-filesize' import peerDepsExternal from 'rollup-plugin-peer-deps-external' import copy from 'rollup-plugin-copy' import svgr from '@svgr/rollup' import url from '@rollup/plugin-url' -const packageJson = require('./package.json') +import packageJson from './package.json' assert { type: 'json' } function rollupPlugins() { return [ url(), svgr(), - json(), + // json(), peerDepsExternal(), resolve(), commonjs(), @@ -24,20 +24,33 @@ function rollupPlugins() { tsconfig: './tsconfig.json', exclude: ['**/__test__/*', '**/__mocks__/*', '**/stories/*'], }), - copy({ - targets: [ - { - src: './src/fonts', - dest: './dist', - }, - ], - }), - terser(), - filesize(), - visualizer(), + // copy({ + // targets: [ + // { + // src: './src/fonts', + // dest: './dist', + // }, + // ], + // }), + // terser(), + // filesize(), + // visualizer(), ] } +// const mainBundle = { +// input: './src/index.ts', +// output: [ +// { +// file: packageJson.module, +// format: 'esm', +// sourcemap: true, +// }, +// ], +// plugins: rollupPlugins(), +// } + +const extensions = ['.ts', '.tsx'] const mainBundle = { input: './src/index.ts', output: [ @@ -45,9 +58,40 @@ const mainBundle = { file: packageJson.module, format: 'esm', sourcemap: true, + interop: 'auto', }, ], - plugins: rollupPlugins(), + // external: ['react', 'styled-components'], + external: ['react', 'styled-components'], + plugins: [ + // peerDepsExternal(), + url(), + svgr(), + json(), + commonjs(), + + // babel({ + // extensions, + // babelHelpers: 'bundled', + // exclude: 'node_modules/**', + // }), + typescript({ + tsconfig: './tsconfig.json', + exclude: ['**/__test__/*', '**/__mocks__/*', '**/stories/*'], + }), + copy({ + targets: [ + { + src: './src/fonts', + dest: './dist', + }, + ], + }), + resolve(), + terser(), + // filesize(), + // visualizer(), + ], } const iconBundle = { @@ -60,37 +104,37 @@ const iconBundle = { }, ], plugins: [ + peerDepsExternal(), url(), svgr(), json(), - peerDepsExternal(), resolve(), - commonjs(), + commonjs({ transformMixedEsModules: true }), typescript({ tsconfig: './icons/tsconfig.json', exclude: ['**/__test__/*', '**/__mocks__/*', '**/stories/*'], }), terser(), - filesize(), - visualizer(), - ] + // filesize(), + // visualizer(), + ], } -const declarationGenerator = { - input: 'dist/esm/src/types/index.d.ts', +const declarationGenerator = { + input: 'dist/esm/types/index.d.ts', output: [{ file: './index.d.ts', format: 'esm' }], plugins: [dts()], -}; +} const iconDeclarationGenerator = { - input: 'dist/esm/src/types/icons/index.d.ts', + input: 'dist/esm/icons/types/index.d.ts', output: [{ file: 'icons/index.d.ts', format: 'esm' }], plugins: [dts()], -}; +} export default [ mainBundle, iconBundle, - declarationGenerator, - iconDeclarationGenerator -] \ No newline at end of file + // declarationGenerator, + // iconDeclarationGenerator, +] diff --git a/src/__test__/Icons.test.tsx b/src/__test__/Icons.test.tsx index abd72b6d..f5b2c475 100644 --- a/src/__test__/Icons.test.tsx +++ b/src/__test__/Icons.test.tsx @@ -1,6 +1,6 @@ import React from 'react' import { render, screen } from '@testing-library/react' -import { Flex } from 'rebass' +import Flex from '../components/Flex' import { CategoryCodeALDR, CategoryCodeANON, diff --git a/src/__test__/index.tsx b/src/__test__/index.tsx index 43a5a3bd..d257c0fb 100644 --- a/src/__test__/index.tsx +++ b/src/__test__/index.tsx @@ -1,7 +1,7 @@ import React, { JSXElementConstructor, ReactElement } from 'react' import { render } from '@testing-library/react' import { ThemeProvider } from 'styled-components' -import theme from '../theme/rebassTheme' +import theme from '../theme/theme' interface IRenderWithWrapper { component: ReactElement> diff --git a/src/bin/create-icons.js b/src/bin/create-icons.js index 81284d9f..7886950f 100644 --- a/src/bin/create-icons.js +++ b/src/bin/create-icons.js @@ -41,7 +41,6 @@ var cleanClipPath = function ($el, $) { } glob(inputRootDir + '/svgs/icons/*.svg', function (err, icons) { - icons.forEach(function (iconPath) { var name = path.basename(iconPath, '.svg') var svg = fs.readFileSync(iconPath, 'utf-8') diff --git a/src/components/Box.tsx b/src/components/Box.tsx new file mode 100644 index 00000000..e4d19b49 --- /dev/null +++ b/src/components/Box.tsx @@ -0,0 +1,41 @@ +import { + compose, + space, + layout, + typography, + color, + flexbox, +} from 'styled-system' +import React from 'react' +import { styled } from 'styled-components' +import css, { get } from '@styled-system/css' +import shouldForwardProp from '@styled-system/should-forward-prop' +import { BoxProps } from 'types' + +const sx = (props) => css(props.sx)(props.theme) +const base = (props) => css(props.__css)(props.theme) +const variant = ({ theme, variant, tx = 'variants' }) => + css(get(theme, `${tx}.${variant}`, get(theme, variant)))(theme) + +const Box = styled('div').withConfig({ shouldForwardProp })( + { + boxSizing: 'border-box', + margin: 0, + minWidth: 0, + }, + base, + variant, + sx, + // (props) => { + // console.log( + // 'props', + // props + // // base(props) + // // compose(space, layout, typography, color, flexbox)(props) + // ) + // }, + (props) => props.css, + compose(space, layout, typography, color, flexbox) +) + +export default Box diff --git a/src/components/Button.tsx b/src/components/Button.tsx index 565f9d5a..b3bcb81c 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -1,46 +1,99 @@ -import React, { FC } from 'react' -import { Button as RButton, ButtonProps } from 'rebass/styled-components' +import React, { forwardRef } from 'react' +import { ButtonProps } from 'types' +import Box from './Box' +type Size = 'small' | 'medium' | 'large' | 'xLarge' | null +type BaseVariants = 'primary' | 'hollow' | 'inverted' | 'link' | 'unstyled' +type Variant = BaseVariants | `${BaseVariants}-disabled` export interface IButton extends ButtonProps { - fontSize?: number - border?: number + disabled?: boolean inverted?: boolean hollow?: boolean - variant?: string + variant?: Variant + btnSize?: Size + onClick?: React.MouseEventHandler } -const Button: FC = (props) => { - let componentVariant = 'primary' +const Button = forwardRef( + ( + { + hollow = false, + inverted = false, + disabled = false, + variant, + btnSize = 'medium', + ...rest + }: IButton, + ref + ) => { + let size = btnSize + let componentVariant = 'primary' + if (variant === 'link' || variant === 'unstyled') size = null - const { hollow, inverted, disabled, variant, border } = props + if (hollow) componentVariant = 'hollow' + if (inverted) componentVariant = 'inverted' + if (disabled) componentVariant += '-disabled' - if (hollow) { - componentVariant = 'hollow' - } - if (inverted) { - componentVariant = 'inverted' - } - if (disabled) { - componentVariant += '-disabled' - } - if (variant !== undefined) { - componentVariant = variant - } + if (variant !== undefined) { + componentVariant = variant + } - return ( - - ) -} + const sizeCss = (s: Size) => { + switch (s) { + case 'small': + return { + fontSize: 14, + height: 32, + px: 3, + } + case 'medium': + return { + fontSize: 1, + height: 40, + px: 24, + } + case 'large': + return { + fontSize: 2, + height: 48, + px: 4, + } + case 'xLarge': + return { + fontSize: 2, + height: 60, + borderRadius: 48, + px: 5, + } + default: + return {} + } + } -Button.defaultProps = { - fontSize: 1, - border: 2, -} + return ( + + ) + } +) export default Button diff --git a/src/components/Checkbox.tsx b/src/components/Checkbox.tsx new file mode 100644 index 00000000..ab3e80ac --- /dev/null +++ b/src/components/Checkbox.tsx @@ -0,0 +1,118 @@ +import React, { forwardRef } from 'react' +import { CheckboxProps, LabelProps } from 'types' +// import { props as systemProps } from '@styled-system/should-forward-prop' +import Box from './Box' +import Label from './Label' + +// const rebassProps = [...systemProps, 'sx', 'variant'] + +// const PRE = new RegExp(`^(${rebassProps.join('|')})$`) + +// const getProps = (test) => (props) => { +// const next = {} +// for (const key in props) { +// if (test(key || '')) next[key] = props[key] +// } +// return next +// } + +// const getSystemProps = getProps((k) => PRE.test(k)) + +export interface ICheckbox extends LabelProps { + // error?: string | undefined + name: string + label: string +} + +const Checkbox = forwardRef( + ( + { className, sx, name, label, variant = 'checkbox', ...props }: ICheckbox, + ref + ) => ( + + ) +) + +export default Checkbox + +// +// +// diff --git a/src/components/Container.tsx b/src/components/Container.tsx index ba2f40e4..c1fb9967 100644 --- a/src/components/Container.tsx +++ b/src/components/Container.tsx @@ -1,8 +1,7 @@ -import React, { FC } from 'react' -import { Box, BoxProps } from 'rebass/styled-components' +import React from 'react' +import { BoxProps } from 'types' +import Box from './Box' -const Container: FC = (props) => ( - -) +const Container = (props: BoxProps) => export default Container diff --git a/src/components/ErrorMessage.tsx b/src/components/ErrorMessage.tsx index aa1edfc8..8a25c8df 100644 --- a/src/components/ErrorMessage.tsx +++ b/src/components/ErrorMessage.tsx @@ -1,23 +1,15 @@ import React, { FC, ReactNode } from 'react' -import { Flex, Box, Text } from 'rebass/styled-components' -import { MdWarning } from 'react-icons/md' +import Text from './Text' interface IErrorMessage { children: ReactNode } -const ErrorMessage: FC = ({ children }) => { +const ErrorMessage = ({ children }: IErrorMessage) => { return ( - - - {children} - - - - - - - + + {children} + ) } diff --git a/src/components/FacebookShareButton.tsx b/src/components/FacebookShareButton.tsx index 382d382d..45b0b9cf 100644 --- a/src/components/FacebookShareButton.tsx +++ b/src/components/FacebookShareButton.tsx @@ -1,15 +1,15 @@ import React, { FC } from 'react' import { FaFacebook } from 'react-icons/fa' -import { Button, ButtonProps, Link } from 'rebass/styled-components' +import { ButtonProps } from 'types' +import Button from './Button' +import Link from './Link' import Text from './Text' export interface IFacebookShareButton extends ButtonProps { url?: string } -const FacebookShareButton: FC = (props) => { - const { url = '', ...rest } = props - +const FacebookShareButton = ({ url = '', ...rest }: IFacebookShareButton) => { let href = 'https://www.facebook.com/sharer/sharer.php?' href += `&u=${encodeURIComponent(url)}` @@ -25,8 +25,4 @@ const FacebookShareButton: FC = (props) => { ) } -FacebookShareButton.defaultProps = { - url: '', -} - export default FacebookShareButton diff --git a/src/components/Flex.tsx b/src/components/Flex.tsx new file mode 100644 index 00000000..a84aff8a --- /dev/null +++ b/src/components/Flex.tsx @@ -0,0 +1,10 @@ +import { FlexProps } from 'types' +import React from 'react' +import { styled } from 'styled-components' +import Box from './Box' + +const Flex = styled(Box)({ + display: 'flex', +}) + +export default Flex diff --git a/src/components/Heading.tsx b/src/components/Heading.tsx index 5061ef32..46025687 100644 --- a/src/components/Heading.tsx +++ b/src/components/Heading.tsx @@ -1,14 +1,12 @@ -import React, { FC } from 'react' -import { TextProps } from 'rebass/styled-components' +import React from 'react' +import { TextProps } from 'types' import Text from './Text' export interface IHeading extends TextProps { h?: number } -const Heading: FC = (props) => { - const { h, ...rest } = props - +const Heading = ({ h = 1, ...rest }: IHeading) => { const getHeadingElement = () => { switch (h) { case 1: @@ -31,8 +29,4 @@ const Heading: FC = (props) => { ) } -Heading.defaultProps = { - h: 1, -} - export default Heading diff --git a/src/components/Hero.tsx b/src/components/Hero.tsx index 91534937..f8886feb 100644 --- a/src/components/Hero.tsx +++ b/src/components/Hero.tsx @@ -1,7 +1,8 @@ -import React, { FC } from 'react' -import { Box, BoxProps } from 'rebass/styled-components' +import React from 'react' +import { BoxProps } from 'types' +import Box from './Box' -const Hero: FC = (props) => { +const Hero = (props: BoxProps) => { return } diff --git a/src/components/HeroLead.tsx b/src/components/HeroLead.tsx index 19a9f3ee..52625ba7 100644 --- a/src/components/HeroLead.tsx +++ b/src/components/HeroLead.tsx @@ -1,9 +1,7 @@ -import React, { FC } from 'react' -import { TextProps } from 'rebass' +import React from 'react' +import { TextProps } from 'types' import Text from './Text' -const HeroLead: FC = (props) => ( - -) +const HeroLead = (props: TextProps) => export default HeroLead diff --git a/src/components/IconButton.tsx b/src/components/IconButton.tsx index 28a1ea62..0c243400 100644 --- a/src/components/IconButton.tsx +++ b/src/components/IconButton.tsx @@ -1,13 +1,11 @@ -import React, { ChangeEvent, FC, ReactNode } from 'react' -import { ButtonProps, Button } from 'rebass/styled-components' +import React, { ReactNode } from 'react' +import Button, { IButton } from './Button' -export interface IIconButton extends ButtonProps { - icon?: ReactNode +export interface IIconButton extends IButton { + icon: ReactNode } -const IconButton: FC = (props) => { - const { icon, ...rest } = props - +const IconButton = ({ icon, ...rest }: IIconButton) => { return ( - -export const Default = Template.bind({}) - -export const Inverted = Template.bind({}) - -export const Hollow = Template.bind({}) - -export const Disabled = Template.bind({}) - -export const ButtonAllProps = Template.bind({}) - -Inverted.args = { - inverted: true, -} - -Hollow.args = { - hollow: true, - border: 6, -} - -Disabled.args = { - disabled: true, -} - -ButtonAllProps.args = { - bg: colors.palette.blue6, - color: colors.palette.yellow4, - fontWeight: 'bold', - height: 60, - mx: 10, - my: 10, - px: 2, - py: 2, - width: 250, -} diff --git a/src/stories/Container.stories.tsx b/src/stories/Container.stories.tsx deleted file mode 100644 index 042867b8..00000000 --- a/src/stories/Container.stories.tsx +++ /dev/null @@ -1,44 +0,0 @@ -import React from 'react' -import { addDecorator, Meta, Story } from '@storybook/react' -import { Box, BoxProps, Flex } from 'rebass/styled-components' -import Container from '../components/Container' -import ThemeDecorator from './ThemeDecorator' -import colors from '../theme/colors' - -const meta: Meta = { - title: 'Container', - component: Container, -} - -addDecorator(ThemeDecorator) - -export default meta - -const Template: Story = (args) => - -export const Default = Template.bind({}) - -Default.args = { - bg: colors.palette.blue6, - width: 1000, - height: 400, -} - -export const ContainerContent = () => { - return ( - - - - {' '} - Page content Page content Page content Page content Page content Page - content Page content Page content{' '} - - - {' '} - Page content Page content Page content Page content Page content Page - content Page content Page content{' '} - - - - ) -} diff --git a/src/stories/FacebookShareButton.stories.tsx b/src/stories/FacebookShareButton.stories.tsx deleted file mode 100644 index aca2cc52..00000000 --- a/src/stories/FacebookShareButton.stories.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import React from 'react' -import { addDecorator, Meta, Story } from '@storybook/react' -import FacebookShareButton, { - IFacebookShareButton, -} from '../components/FacebookShareButton' -import ThemeDecorator from './ThemeDecorator' - -const meta: Meta = { - title: 'FacebookShareButton', - component: FacebookShareButton, - argTypes: { - onClick: { action: 'clicked' }, - }, -} - -addDecorator(ThemeDecorator) - -export default meta - -const Template: Story = (args) => ( - -) - -export const Default = Template.bind({}) - -Default.args = { - url: 'https://www.facebook.com/ooni.org/posts/pfbid0bLKGz5jJ3APvHjT4w4Lnwh4nv1mXTd5TDqoASrebfVgPtySJsS1tKKWVingpcZR6l', -} diff --git a/src/stories/IconButton.stories.tsx b/src/stories/IconButton.stories.tsx deleted file mode 100644 index 8a4533ba..00000000 --- a/src/stories/IconButton.stories.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import React from 'react' -import { addDecorator, Meta } from '@storybook/react' -import { action } from '@storybook/addon-actions' -import { FaAmazon, FaAndroid, FaApple } from 'react-icons/fa' -import IconButton from '../components/IconButton' -import Container from '../components/Container' -import ThemeDecorator from './ThemeDecorator' - -const meta: Meta = { - title: 'IconButton', - component: IconButton, -} - -addDecorator(ThemeDecorator) - -export default meta - -export const Default = () => { - return ( - - } - onClick={action('android clicked')} - /> - } - /> - } - /> - - ) -} diff --git a/src/stories/Input.stories.tsx b/src/stories/Input.stories.tsx deleted file mode 100644 index 9386934e..00000000 --- a/src/stories/Input.stories.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import React from 'react' -import { addDecorator, Meta, Story } from '@storybook/react' -import Input, { IInput } from '../components/Input' -import ThemeDecorator from './ThemeDecorator' - -const meta: Meta = { - title: 'Input', - component: Input, -} - -addDecorator(ThemeDecorator) - -export default meta - -const Template: Story = (args) => ( - -) - -export const Default = Template.bind({}) - -export const ErrorInput = Template.bind({}) - -Default.args = {} - -ErrorInput.args = { - error: 'cannot be empty', -} diff --git a/src/stories/Link.stories.tsx b/src/stories/Link.stories.tsx deleted file mode 100644 index 35a107d7..00000000 --- a/src/stories/Link.stories.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import React from 'react' -import { addDecorator, Meta, Story } from '@storybook/react' -import { Link, LinkProps } from 'rebass/styled-components' -import ThemeDecorator from './ThemeDecorator' - -const meta: Meta = { - title: 'Link', - component: Link, -} - -addDecorator(ThemeDecorator) - -export default meta - -const Template: Story = (args) => Test Link - -export const Default = Template.bind({}) - -export const CustomColor = Template.bind({}) - -export const Attributes = Template.bind({}) - -Default.args = { - href: 'https://ooni.org', -} - -CustomColor.args = { - href: 'https://ooni.org', - color: 'red', -} - -Attributes.args = { - href: 'https://ooni.org', - color: 'green', - target: '_blank', -} diff --git a/src/stories/Modal.stories.tsx b/src/stories/Modal.stories.tsx deleted file mode 100644 index 5b86b768..00000000 --- a/src/stories/Modal.stories.tsx +++ /dev/null @@ -1,63 +0,0 @@ -import React, { useCallback, useState } from 'react' -import { addDecorator, Meta, Story } from '@storybook/react' -import { action } from '@storybook/addon-actions' -import { Box, Button, Flex } from 'rebass/styled-components' -import Modal from '../components/Modal' -import Container from '../components/Container' -import Heading from '../components/Heading' -import ThemeDecorator from './ThemeDecorator' - -const meta: Meta = { - title: 'Modal', - component: Modal, -} - -addDecorator(ThemeDecorator) - -export default meta - -export const Default = () => { - return ( - {}} - bg="red" - sx={{ borderRadius: 20 }} - > - - Modal Content - - - ) -} - -export const CompleteExample = () => { - const [show, setShow] = useState(true) - - const onClose = useCallback(() => { - setShow(false) - action('Clicked') - }, []) - - return ( - - - - {' '} - Page content Page content Page content Page content Page content Page - content Page content Page content{' '} - - {!show && } - - {' '} - Page content Page content Page content Page content Page content Page - content Page content Page content{' '} - - - - Modal Content - - - ) -} diff --git a/src/stories/OONIIcons.stories.tsx b/src/stories/OONIIcons.stories.tsx deleted file mode 100644 index 3c5117b0..00000000 --- a/src/stories/OONIIcons.stories.tsx +++ /dev/null @@ -1,126 +0,0 @@ -import React from 'react' -import { addDecorator, Meta } from '@storybook/react' -import { Box, Flex } from 'rebass/styled-components' -import { - CategoryCodeALDR, - CategoryCodeANON, - CategoryCodeCOMM, - CategoryCodeCOMT, - CategoryCodeCULTR, - CategoryCodeDATE, - CategoryCodeECON, - CategoryCodeENV, - CategoryCodeFILE, - CategoryCodeGAME, - CategoryCodeGMB, - CategoryCodeGOVT, - CategoryCodeGRP, - CategoryCodeHACK, - CategoryCodeHATE, - CategoryCodeHOST, - CategoryCodeHUMR, - CategoryCodeIGO, - CategoryCodeLGBT, - CategoryCodeMILX, - CategoryCodeMISC, - CategoryCodeMMED, - CategoryCodeNEWS, - CategoryCodePOLR, - CategoryCodePORN, - CategoryCodePROV, - CategoryCodePUBH, - CategoryCodeREL, - CategoryCodeSRCH, - CategoryCodeXED, - Cross, - NettestFacebookMessenger, - NettestGroupCircumvention, - NettestGroupExperimental, - NettestGroupInstantMessaging, - NettestGroupMiddleBoxes, - NettestGroupPerformance, - NettestGroupWebsites, - NettestPsiphon, - NettestRiseupVPN, - NettestSignal, - NettestTelegram, - NettestTor, - NettestVanillaTor, - NettestWhatsApp, - Tick, -} from '../components/icons' -import ThemeDecorator from './ThemeDecorator' -import Text from '../components/Text' - -const meta: Meta = { - title: 'OONIIcons', -} - -addDecorator(ThemeDecorator) - -export default meta - -export const Default = () => { - const icons = [ - CategoryCodeALDR, - CategoryCodeANON, - CategoryCodeCOMM, - CategoryCodeCOMT, - CategoryCodeCULTR, - CategoryCodeDATE, - CategoryCodeECON, - CategoryCodeENV, - CategoryCodeFILE, - CategoryCodeGAME, - CategoryCodeGMB, - CategoryCodeGOVT, - CategoryCodeGRP, - CategoryCodeHACK, - CategoryCodeHATE, - CategoryCodeHOST, - CategoryCodeHUMR, - CategoryCodeIGO, - CategoryCodeLGBT, - CategoryCodeMILX, - CategoryCodeMISC, - CategoryCodeMMED, - CategoryCodeNEWS, - CategoryCodePOLR, - CategoryCodePORN, - CategoryCodePROV, - CategoryCodePUBH, - CategoryCodeREL, - CategoryCodeSRCH, - CategoryCodeXED, - Cross, - NettestFacebookMessenger, - NettestGroupCircumvention, - NettestGroupExperimental, - NettestGroupInstantMessaging, - NettestGroupMiddleBoxes, - NettestGroupPerformance, - NettestGroupWebsites, - NettestPsiphon, - NettestRiseupVPN, - NettestSignal, - NettestTelegram, - NettestTor, - NettestVanillaTor, - NettestWhatsApp, - Tick, - ] - - return ( - - {Object.keys(icons).map((k, i) => { - const Icon = icons[i] - return ( - - - {icons[i]} - - ) - })} - - ) -} diff --git a/src/stories/RadioButton.stories.tsx b/src/stories/RadioButton.stories.tsx deleted file mode 100644 index a6dc355b..00000000 --- a/src/stories/RadioButton.stories.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import React from 'react' -import { addDecorator, Meta, Story } from '@storybook/react' -import RadioButton, { IRadioButton } from '../components/RadioButton' -import ThemeDecorator from './ThemeDecorator' - -const meta: Meta = { - title: 'RadioButton', - component: RadioButton, -} - -addDecorator(ThemeDecorator) - -export default meta - -const Template: Story = (args) => - -export const Default = Template.bind({}) - -Default.args = { - label: 'OONI', - name: 'OONI', - id: 'ooni', - value: 'ooni', -} diff --git a/src/stories/RadioGroup.stories.tsx b/src/stories/RadioGroup.stories.tsx deleted file mode 100644 index f93f9255..00000000 --- a/src/stories/RadioGroup.stories.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import React from 'react' -import { addDecorator, Meta, Story } from '@storybook/react' -import { action } from '@storybook/addon-actions' -import RadioGroup, { IRadioGroup } from '../components/RadioGroup' -import RadioButton from '../components/RadioButton' -import ThemeDecorator from './ThemeDecorator' - -const meta: Meta = { - title: 'RadioGroup', - component: RadioGroup, -} - -addDecorator(ThemeDecorator) - -export default meta - -const Template: Story = (args) => { - return ( - - - - - - - ) -} - -export const Default = Template.bind({}) - -Default.args = { - onChange: action('radio option changed'), - name: 'name', -} diff --git a/src/stories/Text.stories.tsx b/src/stories/Text.stories.tsx deleted file mode 100644 index 2f2eece9..00000000 --- a/src/stories/Text.stories.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import React from 'react' -import { addDecorator, Meta, Story } from '@storybook/react' -import { TextProps } from 'rebass' -import Text from '../components/Text' -import ThemeDecorator from './ThemeDecorator' - -const meta: Meta = { - title: 'Text', - component: Text, -} - -addDecorator(ThemeDecorator) - -export default meta - -const Template: Story = (args) => Test Text - -export const Default = Template.bind({}) - -Default.args = { - fontSize: 5, - fontWeight: 'bold', - color: 'primary', -} diff --git a/src/stories/Textarea.stories.tsx b/src/stories/Textarea.stories.tsx deleted file mode 100644 index b03e8002..00000000 --- a/src/stories/Textarea.stories.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import React from 'react' -import { addDecorator, Meta, Story } from '@storybook/react' -import Textarea, { ITextarea } from '../components/Textarea' -import ThemeDecorator from './ThemeDecorator' - -const meta: Meta = { - title: 'Textarea', - component: Textarea, -} - -addDecorator(ThemeDecorator) - -export default meta - -const Template: Story = (args) => ( -