Skip to content

Commit

Permalink
[UI Kit] BalanceInput (#9)
Browse files Browse the repository at this point in the history
* build: Bump storybook

* feat(uikit): BalanceInput

* build: Updated storybook build command

* build: Update storybook command
  • Loading branch information
hachiojidev authored Mar 17, 2021
1 parent f70943e commit 0701ffd
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
run: yarn install

- name: Build Storybook
run: yarn build-storybook
run: yarn storybook:build

- name: Deploy Storybook
uses: peaceiris/actions-gh-pages@v3
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test": "lerna run test",
"lint": "lerna run lint",
"format:check": "lerna run format:check",
"build-storybook": "lerna run build-storybook"
"storybook:build": "lerna run storybook:build"
},
"devDependencies": {
"@babel/core": "^7.12.16",
Expand All @@ -30,11 +30,11 @@
"@pancakeswap-libs/eslint-config-pancake": "0.1.0",
"@rollup/plugin-typescript": "^8.2.0",
"@rollup/plugin-url": "^6.0.0",
"@storybook/addon-a11y": "^6.1.18",
"@storybook/addon-actions": "^6.1.18",
"@storybook/addon-essentials": "^6.1.18",
"@storybook/addon-links": "^6.1.18",
"@storybook/react": "^6.1.18",
"@storybook/addon-a11y": "^6.1.21",
"@storybook/addon-actions": "^6.1.21",
"@storybook/addon-essentials": "^6.1.21",
"@storybook/addon-links": "^6.1.21",
"@storybook/react": "^6.1.21",
"@types/react": "^17.0.2",
"@types/react-router-dom": "^5.1.6",
"@types/react-transition-group": "^4.4.0",
Expand All @@ -50,7 +50,7 @@
"prettier": "^2.1.2",
"react-is": "^17.0.1",
"rollup": "^2.39.0",
"themeprovider-storybook": "^1.6.4",
"themeprovider-storybook": "^1.7.1",
"ts-jest": "^26.5.1",
"tslib": "^2.0.3",
"typescript": "^4.1.5"
Expand Down
3 changes: 0 additions & 3 deletions packages/pancake-uikit/netlify.toml

This file was deleted.

3 changes: 2 additions & 1 deletion packages/pancake-uikit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"repository": "https://github.com/pancakeswap/pancake-uikit",
"license": "MIT",
"scripts": {
"start": "yarn storybook",
"build": "rm -rf ./dist && rollup -c && tsc -d --emitDeclarationOnly --declarationDir dist",
"lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
"format:check": "prettier --check --loglevel error 'src/**/*.{js,jsx,ts,tsx}'",
"format:write": "prettier --write 'src/**/*.{js,jsx,ts,tsx}'",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"storybook:build": "build-storybook",
"test": "jest"
},
"husky": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import { renderWithTheme } from "../../testHelpers";
import BalanceInput from "../../components/BalanceInput/BalanceInput";

const handleChange = jest.fn();

it("renders correctly", () => {
const { asFragment } = renderWithTheme(<BalanceInput value="14" currencyValue="15 USD" onChange={handleChange} />);
expect(asFragment()).toMatchInlineSnapshot(`
<DocumentFragment>
<div
class="sc-gsTCUz sc-hKgILt jLyPtw bSJkHm"
>
<input
class="sc-dlfnbm sc-eCssSg iIlYpN jebGQw"
placeholder="0.0"
scale="md"
type="text"
value="14"
/>
<div
class="sc-bdfBwQ hRRNWZ"
color="textSubtle"
font-size="12px"
>
15 USD
</div>
</div>
</DocumentFragment>
`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";
import Text from "../Text/Text";
import { StyledBalanceInput, StyledInput } from "./styles";
import { BalanceInputProps } from "./types";

const BalanceInput: React.FC<BalanceInputProps> = ({
value,
placeholder = "0.0",
onChange,
currencyValue,
inputProps,
...props
}) => {
return (
<StyledBalanceInput {...props}>
<StyledInput type="text" value={value} onChange={onChange} placeholder={placeholder} {...inputProps} />
{currencyValue && (
<Text fontSize="12px" textAlign="right" color="textSubtle">
{currencyValue}
</Text>
)}
</StyledBalanceInput>
);
};

export default BalanceInput;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { useState } from "react";
import Box from "../Box/Box";
import BalanceInput from "./BalanceInput";

export default {
title: "Components/BalanceInput",
component: BalanceInput,
argTypes: {},
};

export const Default: React.FC = () => {
const [value, setValue] = useState(1.43333);
const currencyValue = `~${(value * 1.3).toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})} USD`;

const handleChange = (evt) => {
setValue(evt.target.value);
};

return (
<Box width="300px">
<BalanceInput value={value} currencyValue={currencyValue} onChange={handleChange} placeholder="0.0" />
</Box>
);
};
2 changes: 2 additions & 0 deletions packages/pancake-uikit/src/components/BalanceInput/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as BalanceInput } from "./BalanceInput";
export type { BalanceInputProps } from "./types";
27 changes: 27 additions & 0 deletions packages/pancake-uikit/src/components/BalanceInput/styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import styled from "styled-components";
import Box from "../Box/Box";
import Input from "../Input/Input";

export const StyledBalanceInput = styled(Box)`
background-color: ${({ theme }) => theme.colors.input};
border-radius: 16px;
box-shadow: ${({ theme }) => theme.shadows.inset};
padding: 8px 16px;
`;

export const StyledInput = styled(Input)`
background: transparent;
border-radius: 0;
box-shadow: none;
padding-left: 0;
padding-right: 0;
text-align: right;
::placeholder {
color: ${({ theme }) => theme.colors.textSubtle};
}
&:focus:not(:disabled) {
box-shadow: none;
}
`;
10 changes: 10 additions & 0 deletions packages/pancake-uikit/src/components/BalanceInput/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { InputHTMLAttributes, ReactNode, ReactText } from "react";
import { BoxProps } from "../Box";

export interface BalanceInputProps extends BoxProps {
value: ReactText;
onChange?: InputHTMLAttributes<HTMLInputElement>["onChange"];
currencyValue?: ReactNode;
placeholder?: string;
inputProps?: Omit<InputHTMLAttributes<HTMLInputElement>, "value" | "placeholder" | "onChange">;
}
1 change: 1 addition & 0 deletions packages/pancake-uikit/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Components
export * from "./components/Alert";
export * from "./components/BalanceInput";
export * from "./components/Box";
export * from "./components/Breadcrumbs";
export * from "./components/Button";
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2547,7 +2547,7 @@
dependencies:
"@sinonjs/commons" "^1.7.0"

"@storybook/addon-a11y@^6.1.18":
"@storybook/addon-a11y@^6.1.21":
version "6.1.21"
resolved "https://registry.yarnpkg.com/@storybook/addon-a11y/-/addon-a11y-6.1.21.tgz#28e44c9f3b7b9e8a319f59b112092fb9aa15fb96"
integrity sha512-FTHQ0QdPhL+0D/E/og/xkT6tIEEOSCgCV+eX9UcDn3shnxVAHEHbqJ7Yf1fF5B/nRx+ptY57c9O64vIFd7UMHg==
Expand All @@ -2569,7 +2569,7 @@
ts-dedent "^2.0.0"
util-deprecate "^1.0.2"

"@storybook/addon-actions@6.1.21", "@storybook/addon-actions@^6.1.18":
"@storybook/addon-actions@6.1.21", "@storybook/addon-actions@^6.1.21":
version "6.1.21"
resolved "https://registry.yarnpkg.com/@storybook/addon-actions/-/addon-actions-6.1.21.tgz#881dceb0ed650fe28086d9993703f8081b29f4ce"
integrity sha512-H+nhSgK3X5L+JfArsC9ufvgJzQwPN9UXBxhMl74faEDCo9RGmq9ywNcjn9XlZGGnJ3jCaYrI/T1u0J7F6PBrTA==
Expand Down Expand Up @@ -2670,7 +2670,7 @@
ts-dedent "^2.0.0"
util-deprecate "^1.0.2"

"@storybook/addon-essentials@^6.1.18":
"@storybook/addon-essentials@^6.1.21":
version "6.1.21"
resolved "https://registry.yarnpkg.com/@storybook/addon-essentials/-/addon-essentials-6.1.21.tgz#ed528fbdebbc841459a8264f74e517c04b0e1a27"
integrity sha512-kdQ/hnfwwodWVFvMdvSbhOyLv/cUJyhgVRyIamrURP9I0OlWhpOAHhwMjAT2KKceutN3UjNpSCqFNSL4dMu25g==
Expand All @@ -2688,7 +2688,7 @@
regenerator-runtime "^0.13.7"
ts-dedent "^2.0.0"

"@storybook/addon-links@^6.1.18":
"@storybook/addon-links@^6.1.21":
version "6.1.21"
resolved "https://registry.yarnpkg.com/@storybook/addon-links/-/addon-links-6.1.21.tgz#59b04c4a0bd1c8dc86fecea64a2531154df382e6"
integrity sha512-DFPK6aYs9VIs1tO0PJ+mBwg64ZLv6NcVwFJ083ghCj/hR+0+3NRox+oRHXCWq7RHtnJeU4VKEiRx2EpE9L9Bkg==
Expand Down Expand Up @@ -2994,7 +2994,7 @@
dependencies:
core-js "^3.0.1"

"@storybook/react@^6.1.18":
"@storybook/react@^6.1.21":
version "6.1.21"
resolved "https://registry.yarnpkg.com/@storybook/react/-/react-6.1.21.tgz#1c4d01dba8d8f130f9b7da4038a380eeb9c61f38"
integrity sha512-j3gq/ssWxRCCH5iCHbP3ihXSGS7lVWh1HpmBmGbbhHGHgdmSPsRjwDXiQGE81EmE7bzbC8NECBhU3zHJ6h1TvA==
Expand Down Expand Up @@ -13831,7 +13831,7 @@ text-table@0.2.0, text-table@^0.2.0:
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
integrity sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=

themeprovider-storybook@^1.6.4:
themeprovider-storybook@^1.7.1:
version "1.7.1"
resolved "https://registry.yarnpkg.com/themeprovider-storybook/-/themeprovider-storybook-1.7.1.tgz#3f95aff1bf049795461a03367ab0ae8b9587400f"
integrity sha512-95LoKUIt+soe4XX7AB2Y58BA0f47bm4cLs9lftkDpa5/ANOm92cXyacESdcQVUy90R4Tx2itfYnp0vTDwZDuRQ==
Expand Down

0 comments on commit 0701ffd

Please sign in to comment.