From a8ec9fb7579a975ccaad897c4827206d32e07ed1 Mon Sep 17 00:00:00 2001 From: Nathan Vasse Date: Wed, 13 Mar 2024 15:29:18 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(react)=20add=20InputPassword?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We had the need to have a built-in password input able to show or hide the password. Closes #301 --- .changeset/flat-guests-matter.md | 5 +++ .../Forms/Input/InputPassword.stories.tsx | 13 ++++++ .../components/Forms/Input/InputPassword.tsx | 41 +++++++++++++++++++ .../src/components/Forms/Input/_index.scss | 7 ++++ .../src/components/Forms/Input/index.mdx | 7 ++++ .../src/components/Forms/Input/index.spec.tsx | 30 ++++++++++++++ packages/react/src/index.ts | 1 + packages/react/src/locales/en-US.json | 6 +++ 8 files changed, 110 insertions(+) create mode 100644 .changeset/flat-guests-matter.md create mode 100644 packages/react/src/components/Forms/Input/InputPassword.stories.tsx create mode 100644 packages/react/src/components/Forms/Input/InputPassword.tsx diff --git a/.changeset/flat-guests-matter.md b/.changeset/flat-guests-matter.md new file mode 100644 index 0000000..1a455c7 --- /dev/null +++ b/.changeset/flat-guests-matter.md @@ -0,0 +1,5 @@ +--- +"@openfun/cunningham-react": minor +--- + +add InputPassword diff --git a/packages/react/src/components/Forms/Input/InputPassword.stories.tsx b/packages/react/src/components/Forms/Input/InputPassword.stories.tsx new file mode 100644 index 0000000..6533989 --- /dev/null +++ b/packages/react/src/components/Forms/Input/InputPassword.stories.tsx @@ -0,0 +1,13 @@ +import { Meta } from "@storybook/react"; +import { InputPassword } from ":/components/Forms/Input/InputPassword"; + +export default { + title: "Components/Forms/Input", + component: InputPassword, +} as Meta; + +export const Password = { + args: { + label: "Your most secret password", + }, +}; diff --git a/packages/react/src/components/Forms/Input/InputPassword.tsx b/packages/react/src/components/Forms/Input/InputPassword.tsx new file mode 100644 index 0000000..6d53695 --- /dev/null +++ b/packages/react/src/components/Forms/Input/InputPassword.tsx @@ -0,0 +1,41 @@ +import React, { forwardRef } from "react"; +import { Input, InputProps } from ":/components/Forms/Input/index"; +import { Button } from ":/components/Button"; +import { useCunningham } from ":/components/Provider"; + +export const InputPassword = forwardRef< + HTMLInputElement, + Omit +>((props: InputProps, ref) => { + const [showPassword, setShowPassword] = React.useState(false); + const { className, ...otherProps } = props; + const customClassName = "c__input--password"; + const { t } = useCunningham(); + return ( + setShowPassword(false)} + icon={visibility_off} + color="tertiary-text" + size="small" + aria-label={t("components.forms.input.password.hide_password")} + /> + ) : ( +