From 94f5ef4924539da16445a9c0b15bb2f8c48bd2e9 Mon Sep 17 00:00:00 2001 From: Josselin TILLAY Date: Fri, 15 Dec 2023 17:00:34 +0100 Subject: [PATCH] :sparkles: Storybook - add date field to storybook --- Storybook/.ondevice/storybook.requires.js | 1 + .../DatePicker/DateField.stories.tsx | 35 +++++++++++++++++++ src/components/datePicker/DateField.tsx | 22 +++++++----- 3 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 Storybook/components/DatePicker/DateField.stories.tsx diff --git a/Storybook/.ondevice/storybook.requires.js b/Storybook/.ondevice/storybook.requires.js index cc9c8612..05fde568 100644 --- a/Storybook/.ondevice/storybook.requires.js +++ b/Storybook/.ondevice/storybook.requires.js @@ -54,6 +54,7 @@ const getStories = () => { "./components/BottomSheet/BottomSheet.stories.tsx": require("../components/BottomSheet/BottomSheet.stories.tsx"), "./components/Button/Button.stories.tsx": require("../components/Button/Button.stories.tsx"), "./components/Card/Card.stories.tsx": require("../components/Card/Card.stories.tsx"), + "./components/DatePicker/DateField.stories.tsx": require("../components/DatePicker/DateField.stories.tsx"), "./components/Dialog/Dialog.stories.tsx": require("../components/Dialog/Dialog.stories.tsx"), "./components/Divider/Divider.stories.tsx": require("../components/Divider/Divider.stories.tsx"), "./components/DropDown/DropDown.stories.tsx": require("../components/DropDown/DropDown.stories.tsx"), diff --git a/Storybook/components/DatePicker/DateField.stories.tsx b/Storybook/components/DatePicker/DateField.stories.tsx new file mode 100644 index 00000000..47dc9112 --- /dev/null +++ b/Storybook/components/DatePicker/DateField.stories.tsx @@ -0,0 +1,35 @@ +import React, { useState } from 'react'; +import { ComponentMeta } from '@storybook/react'; +import { StyleSheet, View } from 'react-native'; +import { DateField } from '../../../src'; +import { DateFieldProps } from '../../../src/components/datePicker/DateField'; + +export default { + title: 'components/DateField', + component: DateField, + argTypes: { + placeholder: { control: { type: 'text' }, defaultValue: '01' }, + hasError: { control: { type: 'boolean' }, defaultValue: false }, + }, + decorators: [ + (Story) => { + const styles = StyleSheet.create({ + container: { + alignItems: 'center', + justifyContent: 'center', + flex: 1, + }, + }); + return ( + + + + ); + }, + ], +} as ComponentMeta; + +export const Default = (args: DateFieldProps) => { + const [value, setValue] = useState(''); + return ; +}; diff --git a/src/components/datePicker/DateField.tsx b/src/components/datePicker/DateField.tsx index f0ef112f..7c98f02c 100644 --- a/src/components/datePicker/DateField.tsx +++ b/src/components/datePicker/DateField.tsx @@ -20,7 +20,7 @@ export interface DateFieldProps extends TextInputProps { hasError?: boolean; } -function GetColorsStyle(theme: Theme, state: State) { +function getColorsStyle(theme: Theme, state: State) { let backgroundColor, borderColor, textColor; switch (state) { @@ -55,7 +55,7 @@ function GetColorsStyle(theme: Theme, state: State) { } function getStyle(theme: Theme, state: State) { - const { backgroundColor, borderColor, textColor } = GetColorsStyle( + const { backgroundColor, borderColor, textColor } = getColorsStyle( theme, state, ); @@ -70,7 +70,7 @@ function getStyle(theme: Theme, state: State) { color: textColor, fontFamily: 'PublicSans-Bold', fontSize: 20, - lineHeight: 48, + lineHeight: 23.5, backgroundColor: backgroundColor, paddingVertical: 0, marginVertical: 0, @@ -144,15 +144,21 @@ function getState( ): State { if (hasError) { return 'error'; - } else if (!isFocused && value === '') { + } + + if (!isFocused && value === '') { return 'empty'; - } else if (isFocused && value === '') { + } + + if (isFocused && value === '') { return 'empty-focused'; - } else if (!isFocused) { + } + + if (!isFocused) { return 'filled'; - } else { - return 'filled-focused'; } + + return 'filled-focused'; } function removeNonNumeric(str: string): string {