-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 💄 Add new AnimatedInputSelect in DS
- Loading branch information
1 parent
fe4a15b
commit 10b75ab
Showing
4 changed files
with
148 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/native-ui": patch | ||
--- | ||
|
||
Add new AnimatedInputSelect in DS |
41 changes: 41 additions & 0 deletions
41
libs/ui/packages/native/src/components/Form/Input/AnimatedInputSelect/Select.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,41 @@ | ||
import styled from "styled-components/native"; | ||
import Flex from "../../../Layout/Flex/index"; | ||
import Text from "../../../Text/index"; | ||
|
||
import ChevronDown from "@ledgerhq/icons-ui/native/ChevronDown"; | ||
import { TouchableOpacity } from "react-native"; | ||
import { BaseStyledProps } from "src/components/styled"; | ||
|
||
const Container = styled(Flex)<{ color: string }>` | ||
border-left-width: 1px; | ||
border-left-color: ${(p) => p.color}; | ||
width: 50%; | ||
`; | ||
|
||
const StyledTouchableOpacity = styled(TouchableOpacity)<BaseStyledProps>` | ||
justify-content: space-between; | ||
flex-direction: row; | ||
align-items: center; | ||
width: 100%; | ||
height: auto; | ||
padding: ${({ theme }) => theme.space[6]}px 0px ${({ theme }) => theme.space[6]}px | ||
${({ theme }) => theme.space[6]}px; | ||
`; | ||
|
||
interface SelectProps { | ||
text: string; | ||
color: string; | ||
|
||
onPressSelect?: () => void; | ||
} | ||
|
||
export const SelectComponent = ({ text, color, onPressSelect }: SelectProps) => { | ||
return ( | ||
<Container color={color}> | ||
<StyledTouchableOpacity onPress={onPressSelect}> | ||
<Text variant="large">{text}</Text> | ||
<ChevronDown /> | ||
</StyledTouchableOpacity> | ||
</Container> | ||
); | ||
}; |
63 changes: 63 additions & 0 deletions
63
libs/ui/packages/native/src/components/Form/Input/AnimatedInputSelect/index.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,63 @@ | ||
import React from "react"; | ||
import { AnimatedInput } from ".."; | ||
import { type InputProps as BaseInputType } from "../BaseInput/index"; | ||
import { useTheme } from "styled-components/native"; | ||
import { StyleProp, ViewStyle, TextInput } from "react-native"; | ||
|
||
import { useAnimatedInputFocus } from "../AnimatedInput/useAnimatedInputFocus"; | ||
import { getInputStatus, inputStatusColors } from "../AnimatedInput/inputTextColor"; | ||
import { SelectComponent } from "./Select"; | ||
|
||
export interface AnimatedInputProps extends BaseInputType { | ||
selectProps: { | ||
onPressSelect?: () => void; | ||
text: string; | ||
}; | ||
style?: StyleProp<ViewStyle>; | ||
} | ||
|
||
const AnimatedInputSelect = ( | ||
{ selectProps, ...textInputProps }: AnimatedInputProps, | ||
ref?: React.ForwardedRef<TextInput> | null, | ||
) => { | ||
const { | ||
placeholder, | ||
onFocus: onFocusCallback, | ||
onBlur: onBlurCallback, | ||
error, | ||
value, | ||
onChange, | ||
...rest | ||
} = textInputProps; | ||
|
||
const { onPressSelect, text } = selectProps; | ||
|
||
const theme = useTheme(); | ||
const { onFocus, onBlur, focused } = useAnimatedInputFocus({ | ||
onFocusCallback, | ||
onBlurCallback, | ||
}); | ||
|
||
const inputStatus = getInputStatus({ focused, hasError: !!error, hasValue: !!value }); | ||
|
||
return ( | ||
<AnimatedInput | ||
value={value} | ||
ref={ref} | ||
onFocus={onFocus} | ||
onBlur={onBlur} | ||
renderRight={() => ( | ||
<SelectComponent | ||
text={text} | ||
color={inputStatusColors[inputStatus]({ theme })} | ||
onPressSelect={onPressSelect} | ||
/> | ||
)} | ||
placeholder={placeholder} | ||
onChange={onChange} | ||
{...rest} | ||
/> | ||
); | ||
}; | ||
|
||
export default React.forwardRef(AnimatedInputSelect); |
39 changes: 39 additions & 0 deletions
39
libs/ui/packages/native/storybook/stories/Form/Input/AnimatedInputAndSelect.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,39 @@ | ||
import React from "react"; | ||
import AnimatedInputSelect from "../../../../src/components/Form/Input/AnimatedInputSelect"; | ||
import { action } from "@storybook/addon-actions"; | ||
|
||
export default { | ||
title: "Form/Input/AnimatedInputSelect", | ||
component: AnimatedInputSelect, | ||
}; | ||
|
||
export const AnimatedInputSelectStory = ( | ||
args: typeof AnimatedInputSelectStoryArgs, | ||
): JSX.Element => { | ||
const [value, setValue] = React.useState(""); | ||
|
||
const onChange = (value: string) => setValue(value); | ||
|
||
return ( | ||
<AnimatedInputSelect | ||
error={args.error} | ||
disabled={args.disabled} | ||
value={value} | ||
onChange={onChange} | ||
placeholder={args.placeholder} | ||
selectProps={args.selectProps} | ||
/> | ||
); | ||
}; | ||
AnimatedInputSelectStory.storyName = "AnimatedInputSelect"; | ||
|
||
const AnimatedInputSelectStoryArgs = { | ||
error: "", | ||
disabled: false, | ||
placeholder: "Edit Tag", | ||
selectProps: { | ||
onPressSelect: () => action("Select"), | ||
text: "Tag type", | ||
}, | ||
}; | ||
AnimatedInputSelectStory.args = AnimatedInputSelectStoryArgs; |