-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb9cda3
commit 1e755e9
Showing
43 changed files
with
36,756 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
"stories": [ | ||
"../src/**/*.stories.mdx", | ||
"../src/**/*.stories.@(js|jsx|ts|tsx)" | ||
], | ||
"addons": [ | ||
"@storybook/addon-links", | ||
"@storybook/addon-essentials", | ||
"@storybook/preset-create-react-app" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
export const parameters = { | ||
actions: { argTypesRegex: "^on[A-Z].*" }, | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,55 @@ | ||
{ | ||
"name": "react-storybook-archref", | ||
"version": "1.0.0", | ||
"description": "This is a template/starter to create a React UI library using Storybook and TypeScript", | ||
"main": "dist/index.js", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"@testing-library/jest-dom": "^5.11.4", | ||
"@testing-library/react": "^11.1.0", | ||
"@testing-library/user-event": "^12.1.10", | ||
"@types/jest": "^26.0.15", | ||
"@types/node": "^12.0.0", | ||
"@types/react": "^17.0.0", | ||
"@types/react-dom": "^17.0.0", | ||
"@types/styled-components": "^5.1.9", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"react-scripts": "4.0.3", | ||
"styled-components": "^5.2.1", | ||
"typescript": "^4.1.2", | ||
"web-vitals": "^1.0.1" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject", | ||
"storybook": "start-storybook -p 6006 -s public", | ||
"build-storybook": "build-storybook -s public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/michaelgudzevskyi/react-storybook-archref.git" | ||
"eslintConfig": { | ||
"extends": [ | ||
"react-app", | ||
"react-app/jest" | ||
] | ||
}, | ||
"keywords": [ | ||
"react", | ||
"storybook", | ||
"typescript", | ||
"ui", | ||
"template", | ||
"starter" | ||
], | ||
"author": "Michael Gudzevskyi", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/michaelgudzevskyi/react-storybook-archref/issues" | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
}, | ||
"homepage": "https://github.com/michaelgudzevskyi/react-storybook-archref#readme", | ||
"devDependencies": { | ||
"@types/react": "^17.0.3", | ||
"react": "^17.0.2", | ||
"typescript": "^4.2.3" | ||
"@storybook/addon-actions": "^6.1.21", | ||
"@storybook/addon-essentials": "^6.1.21", | ||
"@storybook/addon-links": "^6.1.21", | ||
"@storybook/node-logger": "^6.1.21", | ||
"@storybook/preset-create-react-app": "^3.1.7", | ||
"@storybook/react": "^6.1.21" | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta | ||
name="description" | ||
content="Web site created using create-react-app" | ||
/> | ||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> | ||
<!-- | ||
manifest.json provides metadata used when your web app is installed on a | ||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<title>React App</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"short_name": "React App", | ||
"name": "Create React App Sample", | ||
"icons": [ | ||
{ | ||
"src": "favicon.ico", | ||
"sizes": "64x64 32x32 24x24 16x16", | ||
"type": "image/x-icon" | ||
}, | ||
{ | ||
"src": "logo192.png", | ||
"type": "image/png", | ||
"sizes": "192x192" | ||
}, | ||
{ | ||
"src": "logo512.png", | ||
"type": "image/png", | ||
"sizes": "512x512" | ||
} | ||
], | ||
"start_url": ".", | ||
"display": "standalone", | ||
"theme_color": "#000000", | ||
"background_color": "#ffffff" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# https://www.robotstxt.org/robotstxt.html | ||
User-agent: * | ||
Disallow: |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { ElementType, ReactNode, MouseEventHandler, ForwardRefRenderFunction, forwardRef, MutableRefObject } from "react"; | ||
import { StyledButton } from "./styled" | ||
|
||
export type ButtonType = 'default' | 'danger' | 'ghost' | 'secondary'; | ||
|
||
export type ComponentSize = 'default' | 'large' | 'small'; | ||
|
||
interface BaseButtonProps { | ||
type?: ButtonType; | ||
icon?: ElementType; | ||
size?: ComponentSize; | ||
className?: string; | ||
children?: ReactNode; | ||
disabled?: boolean; | ||
loading?: boolean; | ||
} | ||
|
||
type HTMLButtonProps = { | ||
onClick?: MouseEventHandler<HTMLButtonElement>; | ||
} & BaseButtonProps; | ||
|
||
type HTMLAnchorProps = { | ||
href?: string; | ||
} & BaseButtonProps; | ||
|
||
/** | ||
* For React Router Link | ||
*/ | ||
type CustomNodeProps = { | ||
as?: ElementType | ||
to?: string | ||
} & BaseButtonProps | ||
|
||
export type ButtonProps = HTMLButtonProps & HTMLAnchorProps & CustomNodeProps | ||
|
||
const Button: ForwardRefRenderFunction<unknown, ButtonProps> = (props, ref) => { | ||
const { | ||
type = 'default', | ||
icon, | ||
size = 'default', | ||
className, | ||
children, | ||
disabled = false, | ||
loading, | ||
onClick, | ||
href, | ||
as, | ||
to, | ||
} = props; | ||
|
||
const styles = { | ||
innerType: type, | ||
size, | ||
disabled, | ||
withText: children !== null | ||
} | ||
|
||
if (as) { | ||
return ( | ||
<StyledButton | ||
as={as} | ||
to={to} | ||
ref={ref} | ||
className={className} | ||
{...styles} | ||
> | ||
{loading? 'Loading...' : children} | ||
</StyledButton> | ||
) | ||
} | ||
|
||
if (href) { | ||
return ( | ||
<StyledButton | ||
as='a' | ||
href={href} | ||
ref={ref as MutableRefObject<HTMLAnchorElement>} | ||
className={className} | ||
{...styles} | ||
> | ||
{loading? 'Loading...' : children} | ||
</StyledButton> | ||
) | ||
} | ||
|
||
return ( | ||
<StyledButton | ||
as='button' | ||
type='button' | ||
onClick={onClick} | ||
ref={ref as MutableRefObject<HTMLButtonElement>} | ||
className={className} | ||
{...styles} | ||
> | ||
{loading? 'Loading...' : children} | ||
</StyledButton> | ||
) | ||
} | ||
|
||
export default forwardRef<unknown, ButtonProps>(Button) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Button from './button'; | ||
|
||
export * from './button' | ||
|
||
export default Button |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import styled from "styled-components"; | ||
import { ComponentSize, heights, sidePaddings } from "../../config/sizes"; | ||
import { ButtonType } from "./button"; | ||
|
||
type StateColors = { | ||
regular: string; | ||
hover: string; | ||
} | ||
|
||
const typeColors: {[key in ButtonType]: StateColors} = { | ||
default: { | ||
regular: '#0018cf', | ||
hover: '#2e27cc', | ||
}, | ||
danger: { | ||
regular: '#d93848', | ||
hover: '#eb4d5d', | ||
}, | ||
ghost: { | ||
regular: 'transparent', | ||
hover: '#dbdbdb', | ||
}, | ||
secondary: { | ||
regular: '#000', | ||
hover: '#3d3d3d', | ||
} | ||
}; | ||
|
||
interface StyledButtonProps { | ||
innerType: ButtonType; | ||
size: ComponentSize; | ||
withText: boolean; | ||
} | ||
|
||
/* Real tag is assigned dynamically */ | ||
export const StyledButton = styled.button<StyledButtonProps>` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
/* Add margin in case of loading or icon */ | ||
& > *:nth-child(1) { | ||
margin-left: ${pr => pr.withText ? 7 : 0}px; | ||
} | ||
font-size: 15px; | ||
border: none; | ||
cursor: pointer; | ||
background-color: ${ (pr) => typeColors[pr.innerType].regular }; | ||
padding: 0 ${ pr => sidePaddings[pr.size]}px; | ||
height: ${ pr => heights[pr.size]}px; | ||
color: ${ pr => pr.innerType === 'ghost' | ||
? typeColors['default'].regular | ||
: '#fff' | ||
}; | ||
${ pr => pr.disabled ? ` | ||
background-color: #a6a6a6; | ||
color: #5e5e5e; | ||
cursor: not-allowed; | ||
&:hover { | ||
background-color: #a6a6a6 !important; | ||
color: #5e5e5e !important; | ||
} | ||
` : ''} | ||
border-radius: 0; | ||
outline: none; | ||
&:focus { | ||
box-shadow: 0 0 0 1px #fff, 0 0 0 2px ${ (pr) => typeColors[pr.innerType].regular }; | ||
} | ||
&:hover { | ||
background-color: ${ (pr) => typeColors[pr.innerType].hover }; | ||
} | ||
`; | ||
|
||
export const StyledIcon = styled.div` | ||
height: 20px; | ||
`; |
Oops, something went wrong.