Skip to content

Commit

Permalink
feat: 3design からの移行
Browse files Browse the repository at this point in the history
  • Loading branch information
locona committed Jun 3, 2021
1 parent ad44eb5 commit 7221bca
Show file tree
Hide file tree
Showing 20 changed files with 1,541 additions and 285 deletions.
94 changes: 94 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
parser: '@typescript-eslint/parser',
plugins: ['import', '@typescript-eslint', 'unused-imports'],
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:prettier/recommended',
'prettier',
],
parserOptions: {
ecmaFeatures: {
jsx: true,
},
tsconfigRootDir: '.',
},
root: true,
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'react/prop-types': 'off',
'@typescript-eslint/no-var-requires': 0,
'react/display-name': 'off',
'@typescript-eslint/ban-types': [
'error',
{
extendDefaults: true,
types: {
object: false,
},
},
],
'prettier/prettier': [
'error',
{
singleQuote: true,
trailingComma: 'es5',
},
],
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
],
pathGroupsExcludedImportTypes: ['react'],
pathGroups: [
{
pattern: 'react',
group: 'builtin',
position: 'before',
},
{
pattern: '/**',
group: 'internal',
position: 'after',
},
],
alphabetize: { order: 'asc', caseInsensitive: true },
},
],
'@typescript-eslint/no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'warn',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
},
settings: {
react: {
version: 'detect',
},
'import/extensions': ['.ts', '.tsx'],
'import/resolver': {
typescript: {},
},
},
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ yarn-error.log*
package-lock.json

.yalc
yalc.lock
.env

## firebase
Expand Down
27 changes: 20 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@3-shake/3design-ui",
"version": "0.1.12",
"version": "0.1.20",
"main": "dist/index.cjs",
"module": "dist/index.esm.js",
"browser": "dist/index.js",
Expand Down Expand Up @@ -33,9 +33,10 @@
"@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^5.0.0-alpha.28",
"react-detect-offline": "^2.4.3",
"react-dropzone": "^11.3.2",
"react-spinners": "^0.10.6",
"react-table": "^7.6.3",
"react-tabs": "3.2.1",
"react-tabs": "3.2.2",
"twin.macro": "^2.2.3"
},
"devDependencies": {
Expand All @@ -57,13 +58,25 @@
"@storybook/react": "6.1.21",
"@types/react-table": "7.0.29",
"@types/react-tabs": "2.3.2",
"@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "^4.23.0",
"autoprefixer": "10.2.5",
"eslint": "^7.26.0",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.23.2",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.23.2",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-unused-imports": "^1.1.1",
"lint-staged": "^11.0.0",
"namor": "2.0.2",
"postcss": "8.2.14",
"postcss": "8.2.15",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-hook-form": "6.15.4",
"rollup": "2.47.0",
"react-hook-form": "6.15.7",
"rollup": "2.49.0",
"rollup-config-analyzer": "2.2.0",
"rollup-plugin-analyzer": "4.0.0",
"rollup-plugin-filesize": "9.1.1",
Expand All @@ -79,8 +92,8 @@
"peerDependencies": {
"@emotion/react": "11.1.5",
"@emotion/styled": "11.3.0",
"@types/react": "17.0.5",
"@types/react-dom": "17.0.3",
"@types/react": "17.0.6",
"@types/react-dom": "17.0.5",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-hook-form": ">=6.15.4"
Expand Down
66 changes: 66 additions & 0 deletions src/dropzone/Dropzone.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react'
import { Meta } from '@storybook/react/types-6-0'
import tw from 'twin.macro'

import { Dropzone } from './Dropzone'

export default {
title: 'Atom/Dropzone',
component: Dropzone,
decorators: [
(Story: any) => (
<div tw="mt-10 flex flex-col h-screen w-screen gap-4">
<Story />
</div>
),
],
argTypes: {
multiple: { control: 'boolean' },
message: { control: 'text' },
},
} as Meta

export const Basic = ({
multiple,
message,
}: {
multiple: boolean
message: string
}): JSX.Element => {
const [filesState, setFilesState] = React.useState<File[]>([])

const onDrop = React.useCallback(
(files: File[]) => {
if (!multiple && filesState.length > 0) {
return
}
setFilesState((prevState) => [...prevState, ...files])
},
[multiple, filesState.length]
)

const onRemove = React.useCallback(
(file: File) => (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation()
setFilesState((prevState) => {
const newState = [...prevState]
newState.splice(prevState.indexOf(file), 1)
return [...newState]
})
},
[]
)

return (
<Dropzone
multiple={multiple}
message={message}
twin={[
tw`flex justify-center w-auto border border-dotted border-primary-main p-10`,
]}
onDrop={onDrop}
onRemove={onRemove}
files={filesState}
/>
)
}
50 changes: 50 additions & 0 deletions src/dropzone/Dropzone.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react'
import CloseIcon from '@material-ui/icons/Close'
import { useDropzone } from 'react-dropzone'
import { TwStyle } from 'twin.macro'

import { Button } from '../button'

export interface DropzoneProps {
twin?: TwStyle[]
files: File[]
onDrop: (acceptedFiles: File[]) => void
onRemove: (file: File) => (e: React.MouseEvent<HTMLButtonElement>) => void
message?: string
multiple?: boolean
}

export const Dropzone: React.VFC<DropzoneProps> = ({
twin,
files,
onDrop,
onRemove,
message = 'ここにファイルをドロップ',
multiple = false,
}) => {
const { getRootProps, getInputProps } = useDropzone({ onDrop, multiple })

return (
<div {...getRootProps()} css={[twin]} tw="cursor-pointer">
<input {...getInputProps()} />
{files.length > 0 ? (
<div>
{files.map((file) => (
<div key={file.name} tw="flex justify-center items-center">
<div tw="mr-4 flex-1 self-center">{file.name}</div>
<Button
onClick={(e) => onRemove(file)(e)}
color="danger"
variant="text"
>
<CloseIcon className="error w-6 h-6" />
</Button>
</div>
))}
</div>
) : (
<p>{message}</p>
)}
</div>
)
}
1 change: 1 addition & 0 deletions src/dropzone/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Dropzone'
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export * from './tab'
export * from './table'
export * from './tab'
export * from './Modal'
export * from './dropzone'
export * from './loader'
29 changes: 17 additions & 12 deletions src/radio/Radio.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import tw from 'twin.macro'
import { Meta } from '@storybook/react/types-6-0'

import { Radio } from './Radio'
Expand All @@ -20,17 +19,23 @@ export default {
},
} as Meta

export const basic = () => (
<>
<div tw="flex flex-row gap-4">
<RadioGroup label="サービス名">
<Radio label="Relance" value="relance" />
<Radio label="Sreake Sonar" value="sreake-sonar" />
<Radio label="Reckoner" value="reckoner" disabled />
</RadioGroup>
</div>
</>
)
export const Basic = (): JSX.Element => {
const handleRadioChange = (e) => {
console.log(e.target.value)
}

return (
<>
<div tw="flex flex-row gap-4">
<RadioGroup label="サービス名" onChange={handleRadioChange}>
<Radio label="Relance" value="relance" />
<Radio label="Sreake Sonar" value="sreake-sonar" />
<Radio label="Reckoner" value="reckoner" disabled />
</RadioGroup>
</div>
</>
)
}

export const error = () => (
<>
Expand Down
5 changes: 2 additions & 3 deletions src/radio/Radio.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from 'react'
import tw, { css, TwStyle } from 'twin.macro'
import MuiRadio, { RadioProps as MuiRadioProps } from '@material-ui/core/Radio'
import FormControlLabel from '@material-ui/core/FormControlLabel'
import MuiRadio, { RadioProps as MuiRadioProps } from '@material-ui/core/Radio'
import tw, { css, TwStyle } from 'twin.macro'

export interface RadioProps extends MuiRadioProps {
label: string
value: string | number
error?: string

twin?: TwStyle | TwStyle[]
}

Expand Down
21 changes: 14 additions & 7 deletions src/radio/RadioGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import React from 'react'
import tw, { css, TwStyle } from 'twin.macro'
import FormControl from '@material-ui/core/FormControl'
import FormHelperText from '@material-ui/core/FormHelperText'
import MuiRadioGroup, {
RadioGroupProps as MuiRadioGroupProps,
} from '@material-ui/core/RadioGroup'
import FormControl, { FormControlProps } from '@material-ui/core/FormControl'
import FormHelperText from '@material-ui/core/FormHelperText'
import FormLabel from '@material-ui/core/FormLabel'
import tw, { css, TwStyle } from 'twin.macro'

export interface RadioGroupProps extends MuiRadioGroupProps {
children: React.ReactNode
required?: boolean
label?: string
error?: string

twin?: TwStyle | TwStyle[]
children: React.ReactNode
}

export const RadioGroup: React.VFC<RadioGroupProps> = ({
Expand All @@ -23,6 +22,8 @@ export const RadioGroup: React.VFC<RadioGroupProps> = ({
row = true,
error,
children,
onChange,
required = true,
}) => {
return (
<FormControl
Expand All @@ -36,12 +37,18 @@ export const RadioGroup: React.VFC<RadioGroupProps> = ({
`,
]}
>
{label && <FormLabel component="legend">{label}</FormLabel>}
{label && (
<label css={[tw`mb-2 text-middle`]}>
{label}
{required && <span>*</span>}
</label>
)}
<MuiRadioGroup
row={row}
name={name}
defaultValue={defaultValue}
css={[twin]}
onChange={onChange}
>
{children}
</MuiRadioGroup>
Expand Down
Loading

0 comments on commit 7221bca

Please sign in to comment.