diff --git a/example/storybook-nativewind/.storybook/preview.js b/example/storybook-nativewind/.storybook/preview.js index cff2a9ea58..0335b27f39 100644 --- a/example/storybook-nativewind/.storybook/preview.js +++ b/example/storybook-nativewind/.storybook/preview.js @@ -51,11 +51,13 @@ export const parameters = { 'Button', 'Checkbox', 'FormControl', + 'Input', 'Link', 'Pressable', 'Radio', 'Slider', 'Switch', + 'Textarea', ], 'Overlay', ['AlertDialog', 'Modal', 'Popover', 'Tooltip'], diff --git a/example/storybook-nativewind/src/components-example/nativewind/Textarea/index.tsx b/example/storybook-nativewind/src/components-example/nativewind/Textarea/index.tsx index a2e05ce9ea..b5a059c227 100644 --- a/example/storybook-nativewind/src/components-example/nativewind/Textarea/index.tsx +++ b/example/storybook-nativewind/src/components-example/nativewind/Textarea/index.tsx @@ -1,292 +1,84 @@ import React from 'react'; import { createTextarea } from '@gluestack-ui/textarea'; -import { View, TextInput } from 'react-native'; +import { View, TextInput, Platform } from 'react-native'; import { tva, withStyleContextAndStates, useStyleContext, + withStyleContext, + withStates, + cssInterop, + VariantProps, } from '@gluestack-ui/nativewind-utils'; -import { cssInterop } from 'nativewind'; const UITextarea = createTextarea({ // @ts-ignore - Root: withStyleContextAndStates(View), - Input: TextInput, + Root: + Platform.OS === 'web' + ? withStyleContext(View) + : withStyleContextAndStates(View), + Input: Platform.OS === 'web' ? TextInput : withStates(TextInput), }); -// @ts-ignore cssInterop(UITextarea, { className: 'style' }); cssInterop(UITextarea.Input, { className: 'style' }); const textareaStyle = tva({ - base: 'w-full h-[100px] border border-background-300 rounded-sm hover:border-outline-400 hover:border-primary-700 focus:border-primary-700 disabled:opacity-40 disable:border-background-300', + base: 'w-full h-[100px] border border-background-300 rounded hover:border-outline-400 data-[focus=true]:border-primary-700 data-[focus=true]:hover:border-primary-700 data-[disabled=true]:opacity-40 data-[disabled=true]:hover:border-background-300', variants: { - size: { - sm: '', - md: '', - lg: '', - // _input: { - // fontSize: '$lg', - // }, - // { - // _input: { - // fontSize: '$md', - // }, - // }, - // { - // _input: { - // fontSize: '$sm', - // }, - // }, - xl: '', - // { - // _input: { - // fontSize: '$xl', - // }, - // }, - }, variant: { default: - 'focus:border-primary-700 focus:border-primary-700 focus:web:shadows-sm invalid:border-error-700 invalid:web:shadows-sm', - // { - // '_input': { - // _web: { - // outlineWidth: '0', - // outline: 'none', - // }, - // }, - - // ':focus': { - // borderColor: '$primary700', - // _web: { - // boxShadow: 'inset 0 0 0 1px $primary700', - // }, - // }, - - // ':invalid': { - // 'borderColor': '$error700', - // '_web': { - // boxShadow: 'inset 0 0 0 1px $error700', - // }, - // ':hover': { - // borderColor: '$error700', - // }, - // ':focus': { - // ':hover': { - // borderColor: '$primary700', - // _web: { - // boxShadow: 'inset 0 0 0 1px $primary700', - // }, - // }, - // }, - // ':disabled': { - // ':hover': { - // borderColor: '$error700', - // _web: { - // boxShadow: 'inset 0 0 0 1px $error700', - // }, - // }, - // }, - // }, - // }, - }, - - defaultVariants: { - variant: 'default', - size: 'md', + 'data-[focus=true]:border-primary-700 data-[focus=true]:web:ring-1 data-[focus=true]:web:ring-inset data-[focus=true]:web:ring-primary-700 data-[invalid=true]:border-error-700 data-[invalid=true]:web:ring-1 data-[invalid=true]:web:ring-inset data-[invalid=true]:web:ring-error-700 data-[invalid=true]:hover:border-error-700 data-[invalid=true]:data-[focus=true]:hover:border-primary-700 data-[invalid=true]:data-[focus=true]:hover:web:ring-1 data-[invalid=true]:data-[focus=true]:hover:web:ring-inset data-[invalid=true]:data-[focus=true]:hover:web:ring-primary-700 data-[invalid=true]:data-[disabled=true]:hover:border-error-700 data-[invalid=true]:data-[disabled=true]:hover:web:ring-1 data-[invalid=true]:data-[disabled=true]:hover:web:ring-inset data-[invalid=true]:data-[disabled=true]:hover:web:ring-error-700 ', }, }, }); const textareaInputStyle = tva({ - base: 'p-2 flex-1 color-typography-900 align-text-top', - - // / p: '$2', - // color: '$text900', - // textAlignVertical: 'top', - // flex: 1, - - // props: { - // // @ts-ignore - // multiline: true, - // placeholderTextColor: '$text500', - // }, - - // _web: { - // 'cursor': 'text', - // ':disabled': { - // cursor: 'not-allowed', - // }, - // }, - // }, - // { - // ancestorStyle: ['_input'], - // resolveProps: ['placeholderTextColor'], - // }, - // { - // propertyTokenMap: { - // placeholderTextColor: 'colors', - // }, - // } + base: 'p-3 web:outline-0 web:outline-none flex-1 color-typography-900 align-text-top placeholder:text-typography-500 web:cursor-text web:data-[disabled=true]:cursor-not-allowed', + parentVariants: { + size: { + sm: 'text-sm', + md: 'text-base', + lg: 'text-lg', + xl: 'text-xl', + }, + }, }); -// const StyledRoot = -// { - -// '_input': { -// p: '$3', -// _web: { -// outlineWidth: 0, -// outline: 'none', -// }, -// }, - -// ':hover': { -// borderColor: '$border400', -// }, - -// ':focus': { -// 'borderColor': '$primary700', -// ':hover': { -// borderColor: '$primary700', -// }, -// }, - -// ':disabled': { -// 'opacity': 0.4, -// ':hover': { -// borderColor: '$background300', -// }, -// }, - -// 'variants': { -// size: { -// xl: { -// _input: { -// fontSize: '$xl', -// }, -// }, - -// lg: { -// _input: { -// fontSize: '$lg', -// }, -// }, -// md: { -// _input: { -// fontSize: '$md', -// }, -// }, -// sm: { -// _input: { -// fontSize: '$sm', -// }, -// }, -// }, -// variant: { -// default: { -// '_input': { -// _web: { -// outlineWidth: '0', -// outline: 'none', -// }, -// }, - -// ':focus': { -// borderColor: '$primary700', -// _web: { -// boxShadow: 'inset 0 0 0 1px $primary700', -// }, -// }, - -// ':invalid': { -// 'borderColor': '$error700', -// '_web': { -// boxShadow: 'inset 0 0 0 1px $error700', -// }, -// ':hover': { -// borderColor: '$error700', -// }, -// ':focus': { -// ':hover': { -// borderColor: '$primary700', -// _web: { -// boxShadow: 'inset 0 0 0 1px $primary700', -// }, -// }, -// }, -// ':disabled': { -// ':hover': { -// borderColor: '$error700', -// _web: { -// boxShadow: 'inset 0 0 0 1px $error700', -// }, -// }, -// }, -// }, -// }, -// }, -// }, - -// 'defaultProps': { -// variant: 'default', -// size: 'md', -// }, -// }, - -// const StyledInput = styled( -// TextInput, -// { -// p: '$2', -// color: '$text900', -// textAlignVertical: 'top', -// flex: 1, - -// props: { -// // @ts-ignore -// multiline: true, -// placeholderTextColor: '$text500', -// }, - -// _web: { -// 'cursor': 'text', -// ':disabled': { -// cursor: 'not-allowed', -// }, -// }, -// }, -// { -// ancestorStyle: ['_input'], -// resolveProps: ['placeholderTextColor'], -// }, -// { -// propertyTokenMap: { -// placeholderTextColor: 'colors', -// }, -// } -// ); - -export const Textarea = React.forwardRef( - ({ className, variant = 'solid', size = 'md', ...props }: any, ref) => { +type ITextareaProps = React.ComponentProps & + VariantProps; + +const Textarea = React.forwardRef( + ( + { + className, + variant = 'default', + size = 'md', + ...props + }: { className?: string } & ITextareaProps, + ref + ) => { return ( ); } ); -export const TextareaInput = React.forwardRef( - ({ className, variant, size, action, ...props }: any, ref) => { - const { - variant: parentVariant, - size: parentSize, - action: parentAction, - } = useStyleContext(); +type ITextareaInputProps = React.ComponentProps & + VariantProps; + +const TextareaInput = React.forwardRef( + ( + { className, ...props }: { className?: string } & ITextareaInputProps, + ref + ) => { + const { size: parentSize } = useStyleContext(); return ( ); } ); + +Textarea.displayName = 'Textarea'; +TextareaInput.displayName = 'TextareaInput'; + +export { Textarea, TextareaInput }; diff --git a/example/storybook-nativewind/src/components/Textarea/Textarea.tsx b/example/storybook-nativewind/src/components/Textarea/Textarea.tsx index 63fcc05f23..4fb3d21abd 100644 --- a/example/storybook-nativewind/src/components/Textarea/Textarea.tsx +++ b/example/storybook-nativewind/src/components/Textarea/Textarea.tsx @@ -12,7 +12,7 @@ import { Textarea, TextareaInput } from '@/components/ui/Textarea'; const TextareaBasic = ({ ...props }: any) => { return ( - ); diff --git a/example/storybook-nativewind/src/components/Textarea/index.nw.stories.mdx b/example/storybook-nativewind/src/components/Textarea/index.nw.stories.mdx new file mode 100644 index 0000000000..8e88de99df --- /dev/null +++ b/example/storybook-nativewind/src/components/Textarea/index.nw.stories.mdx @@ -0,0 +1,369 @@ +--- +title: gluestack-ui Textarea Component | Installation, Usage, and API + +description: The Textarea component is designed to accommodate larger amounts of text input. It allows multi-line input and can be easily customized to fit the user's needs. + +pageTitle: Textarea + +pageDescription: The Textarea component is designed to accommodate larger amounts of text input. It allows multi-line input and can be easily customized to fit the user's needs. + +showHeader: true +--- + +import { Meta } from '@storybook/addon-docs'; + + + +import { Textarea, TextareaInput } from './Textarea'; +import { + FormControl, + FormControlError, + FormControlLabel, + FormControlLabelText, + FormControlHelper, + FormControlHelperText, +} from '@gluestack-ui/themed'; +import { transformedCode } from '../../utils'; +import { + AppProvider, + CodePreview, + Table, + TableContainer, + InlineCode, +} from '@gluestack/design-system'; + +import Wrapper from '../../components-example/nativewind/Wrapper'; + +This is an illustration of **Textarea** component. + +<> + + + + `, + transformCode: (code) => { + return transformedCode(code); + }, + scope: { + Wrapper, + Textarea, + TextareaInput, + }, + argsType: { + size: { + control: 'select', + options: ['sm', 'md', 'lg', 'xl'], + default: 'md', + }, + isReadOnly: { + control: 'boolean', + options: [true, false], + default: false, + }, + isInvalid: { + control: 'boolean', + options: [true, false], + default: false, + }, + isDisabled: { + control: 'boolean', + options: [true, false], + default: false, + }, + }, + }} + /> + + +
+ +## Installation + +### Step 1: Install the following dependencies: + +```bash + +npm i @gluestack-ui/textarea + +``` + +### Step 2: Copy and paste the following code into your project. + +```jsx +%%-- File: components-example/nativewind/Textarea/index.tsx --%% +``` + +### Step 3: Update the import paths to match your project setup. + +## API Reference + +To use this component in your project, include the following import statement in your file. + +```jsx +import { Textarea } from '@/components/ui/Textarea'; +``` + +```jsx +export default () => ( + +); +``` + +### Component Props + +This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration. + +#### Textarea + +It inherits all the properties of React Native's [View](https://reactnative.dev/docs/view) component. + +<> + + + + + + Prop + + + Type + + + Default + + + Description + + + + + + + + size + + + + 'sm' | 'md' | 'lg' | 'xl' + + + 'md' + + + {`Changes the size of the Input Text`} + + + + + + isInvalid + + + + bool + + + false + + + {`When true, the input displays an error state.`} + + + + + + isDisabled + + + + bool + + + false + + + {`When true, the input is disabled and cannot be edited.`} + + + + + + isHovered + + + + bool + + + false + + + {`When true, the input displays a hover state.`} + + + + + + isFocused + + + + bool + + + false + + + {`When true, the input displays a focus state.`} + + + + + + isRequired + + + + bool + + + false + + + {`If true, sets aria-required="true" on the input.`} + + + + + + isReadOnly + + + + bool + + + false + + + {`If true, the input value cannot be edited.`} + + + +
+
+ + +**Descendants Styling Props** +Props to style child components. + +<> + + + + + + Sx Prop + + + Description + + + + + + + + _input + + + + {`Prop to style TextareaInput Component`} + + + +
+
+ + +#### TextareaInput + +Contains all TextInput related layout style props and actions. +It inherits all the properties of React Native's [TextInput](https://reactnative.dev/docs/textInput) component. + +### Accessibility + +We have outlined the various features that ensure the Textarea component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards. + +#### Keyboard + +- setting the aria-label and aria-hint + +#### Screen Reader + +- VoiceOver: accessible and aria-label props to describe the input's purpose +- `aria-traits` and `aria-hint` for the various states of the input, such as "double tap to edit" + +### Props + +Textarea component is created using TextInput component from react-native. It extends all the props supported by [React Native Text Input](https://reactnative.dev/docs/textinput#props), [utility props](/ui/docs/styling/utility-and-sx-props) and the props mentioned below. + +#### Textarea + +<> + + + + + + Name + + + Value + + + Default + + + + + + + + size + + + + xl | lg | md | sm + + + md + + + +
+
+ + +## Spec Doc + +Explore the comprehensive details of the Input in this document, including its implementation details, checklist, and potential future additions. Dive into the thought process behind the component and gain insights into its development journey. + + diff --git a/example/storybook-nativewind/src/components/Textarea/index.themed.stories.mdx b/example/storybook-nativewind/src/components/Textarea/index.themed.stories.mdx new file mode 100644 index 0000000000..07245e2bac --- /dev/null +++ b/example/storybook-nativewind/src/components/Textarea/index.themed.stories.mdx @@ -0,0 +1,369 @@ +--- +title: gluestack-ui Textarea Component | Installation, Usage, and API + +description: The Textarea component is designed to accommodate larger amounts of text input. It allows multi-line input and can be easily customized to fit the user's needs. + +pageTitle: Textarea + +pageDescription: The Textarea component is designed to accommodate larger amounts of text input. It allows multi-line input and can be easily customized to fit the user's needs. + +showHeader: true +--- + +import { Meta } from '@storybook/addon-docs'; + + + +import { Textarea, TextareaInput } from './Textarea'; +import { + FormControl, + FormControlError, + FormControlLabel, + FormControlLabelText, + FormControlHelper, + FormControlHelperText, +} from '@gluestack-ui/themed'; +import { transformedCode } from '../../utils'; +import { + AppProvider, + CodePreview, + Table, + TableContainer, + InlineCode, +} from '@gluestack/design-system'; + +import Wrapper from '../../components-example/themed/Wrapper'; + +This is an illustration of **Textarea** component. + +<> + + + + `, + transformCode: (code) => { + return transformedCode(code); + }, + scope: { + Wrapper, + Textarea, + TextareaInput, + }, + argsType: { + size: { + control: 'select', + options: ['sm', 'md', 'lg', 'xl'], + default: 'md', + }, + isReadOnly: { + control: 'boolean', + options: [true, false], + default: false, + }, + isInvalid: { + control: 'boolean', + options: [true, false], + default: false, + }, + isDisabled: { + control: 'boolean', + options: [true, false], + default: false, + }, + }, + }} + /> + + +
+ +## Installation + +### Step 1: Install the following dependencies: + +```bash + +npm i @gluestack-ui/textarea + +``` + +### Step 2: Copy and paste the following code into your project. + +```jsx +%%-- File: components-example/themed/Textarea/index.tsx --%% +``` + +### Step 3: Update the import paths to match your project setup. + +## API Reference + +To use this component in your project, include the following import statement in your file. + +```jsx +import { Textarea } from '@/components/ui/Textarea'; +``` + +```jsx +export default () => ( + +); +``` + +### Component Props + +This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration. + +#### Textarea + +It inherits all the properties of React Native's [View](https://reactnative.dev/docs/view) component. + +<> + + + + + + Prop + + + Type + + + Default + + + Description + + + + + + + + size + + + + 'sm' | 'md' | 'lg' | 'xl' + + + 'md' + + + {`Changes the size of the Input Text`} + + + + + + isInvalid + + + + bool + + + false + + + {`When true, the input displays an error state.`} + + + + + + isDisabled + + + + bool + + + false + + + {`When true, the input is disabled and cannot be edited.`} + + + + + + isHovered + + + + bool + + + false + + + {`When true, the input displays a hover state.`} + + + + + + isFocused + + + + bool + + + false + + + {`When true, the input displays a focus state.`} + + + + + + isRequired + + + + bool + + + false + + + {`If true, sets aria-required="true" on the input.`} + + + + + + isReadOnly + + + + bool + + + false + + + {`If true, the input value cannot be edited.`} + + + +
+
+ + +**Descendants Styling Props** +Props to style child components. + +<> + + + + + + Sx Prop + + + Description + + + + + + + + _input + + + + {`Prop to style TextareaInput Component`} + + + +
+
+ + +#### TextareaInput + +Contains all TextInput related layout style props and actions. +It inherits all the properties of React Native's [TextInput](https://reactnative.dev/docs/textInput) component. + +### Accessibility + +We have outlined the various features that ensure the Textarea component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards. + +#### Keyboard + +- setting the aria-label and aria-hint + +#### Screen Reader + +- VoiceOver: accessible and aria-label props to describe the input's purpose +- `aria-traits` and `aria-hint` for the various states of the input, such as "double tap to edit" + +### Props + +Textarea component is created using TextInput component from react-native. It extends all the props supported by [React Native Text Input](https://reactnative.dev/docs/textinput#props), [utility props](/ui/docs/styling/utility-and-sx-props) and the props mentioned below. + +#### Textarea + +<> + + + + + + Name + + + Value + + + Default + + + + + + + + size + + + + xl | lg | md | sm + + + md + + + +
+
+ + +## Spec Doc + +Explore the comprehensive details of the Input in this document, including its implementation details, checklist, and potential future additions. Dive into the thought process behind the component and gain insights into its development journey. + +