From 33231dba7912f7fbfbad249ae7cf9f06a97685ff Mon Sep 17 00:00:00 2001 From: Niels Roozemond Date: Thu, 16 May 2024 12:59:37 +0200 Subject: [PATCH] Added types to text and date inputs --- packages/react/src/DateInput/DateInput.tsx | 9 ++++--- packages/react/src/TextInput/TextInput.tsx | 9 ++++--- .../components/DateInput/DateInput.docs.mdx | 14 ++++++++++ .../DateInput/DateInput.stories.tsx | 18 +++++++++++++ .../components/TextInput/TextInput.docs.mdx | 18 +++++++++++++ .../TextInput/TextInput.stories.tsx | 27 ++++++++++++++++++- 6 files changed, 88 insertions(+), 7 deletions(-) diff --git a/packages/react/src/DateInput/DateInput.tsx b/packages/react/src/DateInput/DateInput.tsx index 6e1c119a9e..7c1241ddc2 100644 --- a/packages/react/src/DateInput/DateInput.tsx +++ b/packages/react/src/DateInput/DateInput.tsx @@ -7,11 +7,14 @@ import clsx from 'clsx' import { forwardRef } from 'react' import type { ForwardedRef, InputHTMLAttributes } from 'react' -export type DateInputProps = InputHTMLAttributes +export type DateInputProps = { + /** The available types are 'date', 'datetime-local', 'month', 'week' */ + type?: 'date' | 'datetime-local' | 'month' | 'week' +} & InputHTMLAttributes export const DateInput = forwardRef( - ({ className, ...restProps }: DateInputProps, ref: ForwardedRef) => ( - + ({ className, type = 'date', ...restProps }: DateInputProps, ref: ForwardedRef) => ( + ), ) diff --git a/packages/react/src/TextInput/TextInput.tsx b/packages/react/src/TextInput/TextInput.tsx index 56990d874a..0a3b5d021f 100644 --- a/packages/react/src/TextInput/TextInput.tsx +++ b/packages/react/src/TextInput/TextInput.tsx @@ -7,11 +7,14 @@ import clsx from 'clsx' import { forwardRef } from 'react' import type { ForwardedRef, InputHTMLAttributes } from 'react' -export type TextInputProps = InputHTMLAttributes +export type TextInputProps = { + /** The options for type in this input are 'text', 'password', 'email, 'tel', 'url' */ + type?: 'text' | 'password' | 'email' | 'tel' | 'url' +} & InputHTMLAttributes export const TextInput = forwardRef( - ({ className, ...restProps }: TextInputProps, ref: ForwardedRef) => ( - + ({ className, type = 'text', ...restProps }: TextInputProps, ref: ForwardedRef) => ( + ), ) diff --git a/storybook/src/components/DateInput/DateInput.docs.mdx b/storybook/src/components/DateInput/DateInput.docs.mdx index 6d734c27d5..08532f3927 100644 --- a/storybook/src/components/DateInput/DateInput.docs.mdx +++ b/storybook/src/components/DateInput/DateInput.docs.mdx @@ -17,3 +17,17 @@ import README from "../../../../packages/css/src/components/date-input/README.md ## Disabled + +## Other Types + +### Local date and time + + + +## Month + + + +## Week + + diff --git a/storybook/src/components/DateInput/DateInput.stories.tsx b/storybook/src/components/DateInput/DateInput.stories.tsx index 43018e8c1d..de9607b67f 100644 --- a/storybook/src/components/DateInput/DateInput.stories.tsx +++ b/storybook/src/components/DateInput/DateInput.stories.tsx @@ -33,3 +33,21 @@ export const Disabled: Story = { disabled: true, }, } + +export const DateTimeLocal: Story = { + args: { + type: 'datetime-local', + }, +} + +export const Month: Story = { + args: { + type: 'month', + }, +} + +export const Week: Story = { + args: { + type: 'week', + }, +} diff --git a/storybook/src/components/TextInput/TextInput.docs.mdx b/storybook/src/components/TextInput/TextInput.docs.mdx index 074011e248..7fcf11a7bd 100644 --- a/storybook/src/components/TextInput/TextInput.docs.mdx +++ b/storybook/src/components/TextInput/TextInput.docs.mdx @@ -32,3 +32,21 @@ Incorrectly filled input fields become visible immediately. ### Disabled + +## Other Types + +### Password + + + +### Email + + + +## Tel + + + +### URL + + diff --git a/storybook/src/components/TextInput/TextInput.stories.tsx b/storybook/src/components/TextInput/TextInput.stories.tsx index 73a1297b6e..b935f0a547 100644 --- a/storybook/src/components/TextInput/TextInput.stories.tsx +++ b/storybook/src/components/TextInput/TextInput.stories.tsx @@ -30,7 +30,7 @@ const meta = { Toggling the invalid control sets the required attribute on the input and requires it to match "ž". Wrapped in a form, this triggers the invalid state. */} - + ) }, @@ -51,6 +51,7 @@ export const Placeholder: Story = { export const Invalid: Story = { args: { invalid: true, + pattern: '[ž]', }, } @@ -59,3 +60,27 @@ export const Disabled: Story = { disabled: true, }, } + +export const Password: Story = { + args: { + type: 'password', + }, +} + +export const Email: Story = { + args: { + type: 'email', + }, +} + +export const Tel: Story = { + args: { + type: 'tel', + }, +} + +export const Url: Story = { + args: { + type: 'url', + }, +}