Skip to content

Commit

Permalink
feat: Add space props from styled-system (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
RabbitDoge authored Nov 5, 2020
1 parent 62bbb56 commit ce4cc9a
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 4 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@storybook/react": "^6.0.26",
"@types/react": "^16.9.52",
"@types/styled-components": "^5.1.4",
"@types/styled-system": "^5.1.10",
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.4.1",
"babel-loader": "^8.1.0",
Expand Down Expand Up @@ -70,6 +71,7 @@
},
"dependencies": {
"@types/lodash": "^4.14.162",
"lodash": "^4.17.20"
"lodash": "^4.17.20",
"styled-system": "^5.1.5"
}
}
2 changes: 2 additions & 0 deletions src/components/Button/StyledButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled, { DefaultTheme } from "styled-components";
import { space } from "styled-system";
import { ButtonProps, ButtonThemeVariant, variants } from "./types";

interface ThemedProps extends ButtonProps {
Expand Down Expand Up @@ -60,6 +61,7 @@ const StyledButton = styled.button<ButtonProps>`
color: ${({ theme }) => theme.colors.textDisabled};
cursor: not-allowed;
}
${space}
`;

StyledButton.defaultProps = {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Button/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ButtonHTMLAttributes, ReactNode } from "react";
import { SpaceProps } from "styled-system";

export const sizes = {
SM: "sm",
Expand All @@ -15,7 +16,7 @@ export const variants = {
export type Sizes = typeof sizes[keyof typeof sizes];
export type Variants = typeof variants[keyof typeof variants];

export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement>, SpaceProps {
variant?: Variants;
size?: Sizes;
startIcon?: ReactNode;
Expand Down
4 changes: 3 additions & 1 deletion src/components/Svg/Svg.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { SVGAttributes } from "react";
import styled, { DefaultTheme } from "styled-components";
import { space, SpaceProps } from "styled-system";
import getThemeValue from "../../util/getThemeValue";

export interface Props extends SVGAttributes<HTMLOrSVGElement> {
export interface Props extends SVGAttributes<HTMLOrSVGElement>, SpaceProps {
theme: DefaultTheme;
}

const Svg = styled.svg.attrs({ xmlns: "http://www.w3.org/2000/svg" })<Props>`
fill: ${({ theme, color }) => getThemeValue(`colors.${color}`, color)(theme)};
${space}
`;

Svg.defaultProps = {
Expand Down
4 changes: 3 additions & 1 deletion src/components/Text/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled, { DefaultTheme } from "styled-components";
import { space, SpaceProps } from "styled-system";

export interface Props {
export interface Props extends SpaceProps {
color?: string;
fontSize?: string;
bold?: boolean;
Expand All @@ -23,6 +24,7 @@ const Text = styled.div<Props>`
font-size: ${getFontSize};
font-weight: ${({ bold }) => (bold ? 600 : 400)};
line-height: 1.5;
${space}
`;

export default Text;
116 changes: 116 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2231,6 +2231,96 @@
resolve-from "^5.0.0"
store2 "^2.7.1"

"@styled-system/background@^5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@styled-system/background/-/background-5.1.2.tgz#75c63d06b497ab372b70186c0bf608d62847a2ba"
integrity sha512-jtwH2C/U6ssuGSvwTN3ri/IyjdHb8W9X/g8Y0JLcrH02G+BW3OS8kZdHphF1/YyRklnrKrBT2ngwGUK6aqqV3A==
dependencies:
"@styled-system/core" "^5.1.2"

"@styled-system/border@^5.1.5":
version "5.1.5"
resolved "https://registry.yarnpkg.com/@styled-system/border/-/border-5.1.5.tgz#0493d4332d2b59b74bb0d57d08c73eb555761ba6"
integrity sha512-JvddhNrnhGigtzWRCVuAHepniyVi6hBlimxWDVAdcTuk7aRn9BYJUwfHslURtwYFsF5FoEs8Zmr1oZq2M1AP0A==
dependencies:
"@styled-system/core" "^5.1.2"

"@styled-system/color@^5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@styled-system/color/-/color-5.1.2.tgz#b8d6b4af481faabe4abca1a60f8daa4ccc2d9f43"
integrity sha512-1kCkeKDZkt4GYkuFNKc7vJQMcOmTl3bJY3YBUs7fCNM6mMYJeT1pViQ2LwBSBJytj3AB0o4IdLBoepgSgGl5MA==
dependencies:
"@styled-system/core" "^5.1.2"

"@styled-system/core@^5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@styled-system/core/-/core-5.1.2.tgz#b8b7b86455d5a0514f071c4fa8e434b987f6a772"
integrity sha512-XclBDdNIy7OPOsN4HBsawG2eiWfCcuFt6gxKn1x4QfMIgeO6TOlA2pZZ5GWZtIhCUqEPTgIBta6JXsGyCkLBYw==
dependencies:
object-assign "^4.1.1"

"@styled-system/css@^5.1.5":
version "5.1.5"
resolved "https://registry.yarnpkg.com/@styled-system/css/-/css-5.1.5.tgz#0460d5f3ff962fa649ea128ef58d9584f403bbbc"
integrity sha512-XkORZdS5kypzcBotAMPBoeckDs9aSZVkvrAlq5K3xP8IMAUek+x2O4NtwoSgkYkWWzVBu6DGdFZLR790QWGG+A==

"@styled-system/flexbox@^5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@styled-system/flexbox/-/flexbox-5.1.2.tgz#077090f43f61c3852df63da24e4108087a8beecf"
integrity sha512-6hHV52+eUk654Y1J2v77B8iLeBNtc+SA3R4necsu2VVinSD7+XY5PCCEzBFaWs42dtOEDIa2lMrgL0YBC01mDQ==
dependencies:
"@styled-system/core" "^5.1.2"

"@styled-system/grid@^5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@styled-system/grid/-/grid-5.1.2.tgz#7165049877732900b99cd00759679fbe45c6c573"
integrity sha512-K3YiV1KyHHzgdNuNlaw8oW2ktMuGga99o1e/NAfTEi5Zsa7JXxzwEnVSDSBdJC+z6R8WYTCYRQC6bkVFcvdTeg==
dependencies:
"@styled-system/core" "^5.1.2"

"@styled-system/layout@^5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@styled-system/layout/-/layout-5.1.2.tgz#12d73e79887e10062f4dbbbc2067462eace42339"
integrity sha512-wUhkMBqSeacPFhoE9S6UF3fsMEKFv91gF4AdDWp0Aym1yeMPpqz9l9qS/6vjSsDPF7zOb5cOKC3tcKKOMuDCPw==
dependencies:
"@styled-system/core" "^5.1.2"

"@styled-system/position@^5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@styled-system/position/-/position-5.1.2.tgz#56961266566836f57a24d8e8e33ce0c1adb59dd3"
integrity sha512-60IZfMXEOOZe3l1mCu6sj/2NAyUmES2kR9Kzp7s2D3P4qKsZWxD1Se1+wJvevb+1TP+ZMkGPEYYXRyU8M1aF5A==
dependencies:
"@styled-system/core" "^5.1.2"

"@styled-system/shadow@^5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@styled-system/shadow/-/shadow-5.1.2.tgz#beddab28d7de03cd0177a87ac4ed3b3b6d9831fd"
integrity sha512-wqniqYb7XuZM7K7C0d1Euxc4eGtqEe/lvM0WjuAFsQVImiq6KGT7s7is+0bNI8O4Dwg27jyu4Lfqo/oIQXNzAg==
dependencies:
"@styled-system/core" "^5.1.2"

"@styled-system/space@^5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@styled-system/space/-/space-5.1.2.tgz#38925d2fa29a41c0eb20e65b7c3efb6e8efce953"
integrity sha512-+zzYpR8uvfhcAbaPXhH8QgDAV//flxqxSjHiS9cDFQQUSznXMQmxJegbhcdEF7/eNnJgHeIXv1jmny78kipgBA==
dependencies:
"@styled-system/core" "^5.1.2"

"@styled-system/typography@^5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@styled-system/typography/-/typography-5.1.2.tgz#65fb791c67d50cd2900d234583eaacdca8c134f7"
integrity sha512-BxbVUnN8N7hJ4aaPOd7wEsudeT7CxarR+2hns8XCX1zp0DFfbWw4xYa/olA0oQaqx7F1hzDg+eRaGzAJbF+jOg==
dependencies:
"@styled-system/core" "^5.1.2"

"@styled-system/variant@^5.1.5":
version "5.1.5"
resolved "https://registry.yarnpkg.com/@styled-system/variant/-/variant-5.1.5.tgz#8446d8aad06af3a4c723d717841df2dbe4ddeafd"
integrity sha512-Yn8hXAFoWIro8+Q5J8YJd/mP85Teiut3fsGVR9CAxwgNfIAiqlYxsk5iHU7VHJks/0KjL4ATSjmbtCDC/4l1qw==
dependencies:
"@styled-system/core" "^5.1.2"
"@styled-system/css" "^5.1.5"

"@svgr/babel-plugin-add-jsx-attribute@^5.4.0":
version "5.4.0"
resolved "https://registry.yarnpkg.com/@svgr/babel-plugin-add-jsx-attribute/-/babel-plugin-add-jsx-attribute-5.4.0.tgz#81ef61947bb268eb9d50523446f9c638fb355906"
Expand Down Expand Up @@ -2679,6 +2769,13 @@
"@types/react-native" "*"
csstype "^3.0.2"

"@types/styled-system@^5.1.10":
version "5.1.10"
resolved "https://registry.yarnpkg.com/@types/styled-system/-/styled-system-5.1.10.tgz#dcf5690dd837ca49b8de1f23cb99d510c7f4ecb3"
integrity sha512-OmVjC9OzyUckAgdavJBc+t5oCJrNXTlzWl9vo2x47leqpX1REq2qJC49SEtzbu1OnWSzcD68Uq3Aj8TeX+Kvtg==
dependencies:
csstype "^3.0.2"

"@types/tapable@*", "@types/tapable@^1.0.5":
version "1.0.6"
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.6.tgz#a9ca4b70a18b270ccb2bc0aaafefd1d486b7ea74"
Expand Down Expand Up @@ -12279,6 +12376,25 @@ styled-react-modal@^2.0.1:
resolved "https://registry.yarnpkg.com/styled-react-modal/-/styled-react-modal-2.0.1.tgz#513d47bdbdba67f474a8a4dfeb13d072a172c7fc"
integrity sha512-uoyPlwdM8FLmdOE8dvA3iv2IOnlqMsygPxLAZy8WaK0pEcon67+SWJY/osAWZuBvRKtSo/VXn1fRCYVgbD0KUQ==

styled-system@^5.1.5:
version "5.1.5"
resolved "https://registry.yarnpkg.com/styled-system/-/styled-system-5.1.5.tgz#e362d73e1dbb5641a2fd749a6eba1263dc85075e"
integrity sha512-7VoD0o2R3RKzOzPK0jYrVnS8iJdfkKsQJNiLRDjikOpQVqQHns/DXWaPZOH4tIKkhAT7I6wIsy9FWTWh2X3q+A==
dependencies:
"@styled-system/background" "^5.1.2"
"@styled-system/border" "^5.1.5"
"@styled-system/color" "^5.1.2"
"@styled-system/core" "^5.1.2"
"@styled-system/flexbox" "^5.1.2"
"@styled-system/grid" "^5.1.2"
"@styled-system/layout" "^5.1.2"
"@styled-system/position" "^5.1.2"
"@styled-system/shadow" "^5.1.2"
"@styled-system/space" "^5.1.2"
"@styled-system/typography" "^5.1.2"
"@styled-system/variant" "^5.1.5"
object-assign "^4.1.1"

supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
Expand Down

0 comments on commit ce4cc9a

Please sign in to comment.