-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* build: Bump storybook * feat(uikit): BalanceInput * build: Updated storybook build command * build: Update storybook command
- Loading branch information
1 parent
f70943e
commit 0701ffd
Showing
12 changed files
with
140 additions
and
18 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
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
31 changes: 31 additions & 0 deletions
31
packages/pancake-uikit/src/__tests__/components/balanceinput.test.tsx
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,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> | ||
`); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/pancake-uikit/src/components/BalanceInput/BalanceInput.tsx
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,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; |
27 changes: 27 additions & 0 deletions
27
packages/pancake-uikit/src/components/BalanceInput/index.stories.tsx
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,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> | ||
); | ||
}; |
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,2 @@ | ||
export { default as BalanceInput } from "./BalanceInput"; | ||
export type { BalanceInputProps } from "./types"; |
27 changes: 27 additions & 0 deletions
27
packages/pancake-uikit/src/components/BalanceInput/styles.tsx
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,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
10
packages/pancake-uikit/src/components/BalanceInput/types.ts
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,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">; | ||
} |
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