From feea284ec8995ba5670221cf3fbb1503534c44c2 Mon Sep 17 00:00:00 2001 From: Nathan Vasse Date: Fri, 14 Apr 2023 16:38:58 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(react)=20add=20Input=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Finally the first form component of the design system. It wraps and enhance the native input element. --- .changeset/grumpy-otters-sniff.md | 5 + .../src/components/Forms/Input/index.scss | 125 +++++++++-- .../src/components/Forms/Input/index.spec.tsx | 184 ++++++++++++++++ .../components/Forms/Input/index.stories.mdx | 160 ++++++++++++++ .../components/Forms/Input/index.stories.tsx | 203 +++++++++++++++++- .../src/components/Forms/Input/index.tsx | 149 ++++++++++++- .../components/Forms/Input/resources/dd_1.svg | 48 +++++ .../components/Forms/Input/resources/dd_2.svg | 49 +++++ .../components/Forms/Input/resources/dd_3.svg | 83 +++++++ .../components/Forms/Input/resources/dd_4.svg | 38 ++++ .../components/Forms/Input/resources/dd_5.svg | 36 ++++ .../components/Forms/Input/resources/dd_6.svg | 30 +++ .../src/components/Forms/Input/tokens.ts | 15 ++ packages/react/src/cunningham-tokens.css | 14 ++ packages/react/src/cunningham-tokens.js | 2 +- packages/react/src/cunningham-tokens.ts | 2 +- packages/react/src/index.ts | 1 + packages/react/src/utils/index.ts | 9 + 18 files changed, 1121 insertions(+), 32 deletions(-) create mode 100644 .changeset/grumpy-otters-sniff.md create mode 100644 packages/react/src/components/Forms/Input/index.spec.tsx create mode 100644 packages/react/src/components/Forms/Input/index.stories.mdx create mode 100644 packages/react/src/components/Forms/Input/resources/dd_1.svg create mode 100644 packages/react/src/components/Forms/Input/resources/dd_2.svg create mode 100644 packages/react/src/components/Forms/Input/resources/dd_3.svg create mode 100644 packages/react/src/components/Forms/Input/resources/dd_4.svg create mode 100644 packages/react/src/components/Forms/Input/resources/dd_5.svg create mode 100644 packages/react/src/components/Forms/Input/resources/dd_6.svg create mode 100644 packages/react/src/components/Forms/Input/tokens.ts diff --git a/.changeset/grumpy-otters-sniff.md b/.changeset/grumpy-otters-sniff.md new file mode 100644 index 0000000..64a0fbf --- /dev/null +++ b/.changeset/grumpy-otters-sniff.md @@ -0,0 +1,5 @@ +--- +"@openfun/cunningham-react": minor +--- + +Add Input component diff --git a/packages/react/src/components/Forms/Input/index.scss b/packages/react/src/components/Forms/Input/index.scss index 87355ad..5c72669 100644 --- a/packages/react/src/components/Forms/Input/index.scss +++ b/packages/react/src/components/Forms/Input/index.scss @@ -1,23 +1,116 @@ -.c__input { - height: 2rem; - padding: 0 14px; - box-sizing: border-box; - border-radius: 2px; - border: 1px var(--c--theme--colors--greyscale-300) solid; +.c__input__wrapper { + + border-radius: var(--c--components--forms-input--border-radius); + border-width: var(--c--components--forms-input--border-width); + border-color: var(--c--components--forms-input--border-color); + border-style: var(--c--components--forms-input--border-style); + display: flex; + align-items: center; transition: border var(--c--theme--transitions--duration) var(--c--theme--transitions--ease-out); - color: var(--c--theme--colors--greyscale-800); - font-size: var(--c--theme--font--sizes--m); + padding: 0 1rem; + gap: 1rem; + cursor: text; + color: var(--c--components--forms-input--color); + box-sizing: border-box; + height: 3.5rem; - &:focus { - outline: 0; - border: 1px var(--c--theme--colors--greyscale-500) solid; + %text-style { + font-size: var(--c--components--forms-input--font-size); + font-weight: var(--c--components--forms-input--font-weight); } - &--medium { - min-width: 150px; + .c__input__inner { + position: relative; + flex-grow: 1; + display: flex; + height: 100%; + + .c__input { + + box-sizing: border-box; + outline: 0; + border: none; + padding: 1rem 0 0 0; + color: var(--c--theme--colors--greyscale-800); + flex-grow: 1; + text-overflow: ellipsis; + background-color: transparent; + @extend %text-style; + + &--medium { + min-width: 150px; + } + + &--nano { + min-width: 10px; + } + } + + label { + position: absolute; + font-size: var(--c--theme--font--sizes--s); + left: 0; + top: 0.75rem; + transition: all var(--c--theme--transitions--duration) var(--c--theme--transitions--ease-out); + color: var(--c--theme--colors--greyscale-600); + + &.placeholder { + @extend %text-style; + top: 18px; + } + } } - &--nano { - min-width: 10px; + &:hover { + border-radius: var(--c--components--forms-input--border-radius--hover); + border-color: var(--c--components--forms-input--border-color--hover); } -} \ No newline at end of file + + /** Modifiers. */ + + &--full-width { + width: 100%; + } + + &:focus-within { + border-radius: var(--c--components--forms-input--border-radius--focus); + border-color: var(--c--components--forms-input--border-color--focus) !important; + } + + &--disabled { + cursor: default; + color: var(--c--theme--colors--greyscale-400); + border-color: var(--c--theme--colors--greyscale-200); + + .c__input__inner { + .c__input, label { + color: var(--c--theme--colors--greyscale-600); + } + } + + &:hover { + border-color: var(--c--theme--colors--greyscale-200); + } + } + + &--success { + border-color: var(--c--theme--colors--success-600); + + &:not(.c__input__wrapper--disabled) { + &:hover { + border-color: var(--c--theme--colors--success-400); + } + } + } + + &--error { + border-color: var(--c--theme--colors--danger-600); + + &:not(.c__input__wrapper--disabled) { + &:hover { + border-color: var(--c--theme--colors--danger-200); + } + } + } +} + diff --git a/packages/react/src/components/Forms/Input/index.spec.tsx b/packages/react/src/components/Forms/Input/index.spec.tsx new file mode 100644 index 0000000..9e0f6f3 --- /dev/null +++ b/packages/react/src/components/Forms/Input/index.spec.tsx @@ -0,0 +1,184 @@ +import { render, screen } from "@testing-library/react"; +import React, { useRef } from "react"; +import userEvent from "@testing-library/user-event"; +import { expect } from "vitest"; +import { Input, InputRefType } from "components/Forms/Input/index"; +import { Button } from "components/Button"; + +describe("", () => { + it("renders and can type", async () => { + const user = userEvent.setup(); + render(); + const input: HTMLInputElement = screen.getByRole("textbox", { + name: "First name", + }); + expect(input.value).toEqual(""); + await user.type(input, "John"); + expect(input.value).toEqual("John"); + }); + it("renders with default value and can type", async () => { + const user = userEvent.setup(); + render(); + const input: HTMLInputElement = screen.getByRole("textbox", { + name: "First name", + }); + + expect(input.value).toEqual("John"); + await user.clear(input); + expect(input.value).toEqual(""); + await user.type(input, "Paul"); + expect(input.value).toEqual("Paul"); + }); + it("renders with moving label", async () => { + const user = userEvent.setup(); + render( +
+ + +
+ ); + const input: HTMLInputElement = screen.getByRole("textbox", { + name: "First name", + }); + const input2: HTMLInputElement = screen.getByRole("textbox", { + name: "Second name", + }); + const label = screen.getByText("First name"); + expect(Array.from(label.classList)).toContain("placeholder"); + // Clicking on the input should remove the placeholder class. + await user.click(input); + expect(Array.from(label.classList)).not.toContain("placeholder"); + // Writing something should remove the placeholder class too. + await user.type(input, "John"); + expect(Array.from(label.classList)).not.toContain("placeholder"); + // Clearing the input and focus out should add the placeholder class + await user.clear(input); + await user.click(input2); + expect(Array.from(label.classList)).toContain("placeholder"); + }); + it("renders with state=success", async () => { + render(); + expect(document.querySelector(".c__field--success")).toBeInTheDocument(); + expect( + document.querySelector(".c__input__wrapper--success") + ).toBeInTheDocument(); + }); + it("renders with state=error", async () => { + render(); + expect(document.querySelector(".c__field--error")).toBeInTheDocument(); + expect( + document.querySelector(".c__input__wrapper--error") + ).toBeInTheDocument(); + }); + it("renders disabled", async () => { + const user = userEvent.setup(); + render(); + const input: HTMLInputElement = screen.getByRole("textbox", { + name: "First name", + }); + expect( + document.querySelector(".c__input__wrapper--disabled") + ).toBeInTheDocument(); + expect(input.value).toEqual(""); + // Disabled inputs should not be able to type. + await user.type(input, "John"); + expect(input.value).toEqual(""); + }); + it("renders with left icon", async () => { + render( + apartment} + /> + ); + expect(document.querySelector(".material-icons")).toBeInTheDocument(); + }); + it("renders with right icon", async () => { + render( + apartment} + /> + ); + expect(document.querySelector(".material-icons")).toBeInTheDocument(); + }); + it("renders with text", async () => { + render( + apartment} + text="Some text" + /> + ); + screen.getByText("Some text"); + }); + it("renders with text and text right", async () => { + render( + apartment} + rightText="Some text right" + /> + ); + screen.getByText("Some text right"); + }); + it("renders with char counter", async () => { + const user = userEvent.setup(); + render(); + const input: HTMLInputElement = screen.getByRole("textbox", { + name: "First name", + }); + screen.getByText("0/15"); + await user.type(input, "Jo"); + screen.getByText("2/15"); + await user.type(input, "hn"); + screen.getByText("4/15"); + await user.clear(input); + screen.getByText("0/15"); + }); + it("forwards ref", async () => { + const user = userEvent.setup(); + const Wrapper = () => { + const ref = useRef(null); + return ( +
+ + +
+ ); + }; + render(); + const input: HTMLInputElement = screen.getByRole("textbox", { + name: "First name", + }); + expect(input).not.toHaveFocus(); + await user.click(screen.getByRole("button", { name: "Focus" })); + expect(input).toHaveFocus(); + }); + it("works controlled", async () => { + const Wrapper = () => { + const [value, setValue] = React.useState("I am controlled"); + return ( +
+
Value: {value}.
+ setValue(e.target.value)} + /> + +
+ ); + }; + const user = userEvent.setup(); + render(); + const input: HTMLInputElement = screen.getByRole("textbox", { + name: "First name", + }); + screen.getByText("Value: I am controlled."); + await user.type(input, "John"); + screen.getByText("Value: I am controlledJohn."); + await user.clear(input); + screen.getByText("Value: ."); + }); +}); diff --git a/packages/react/src/components/Forms/Input/index.stories.mdx b/packages/react/src/components/Forms/Input/index.stories.mdx new file mode 100644 index 0000000..d5cfe78 --- /dev/null +++ b/packages/react/src/components/Forms/Input/index.stories.mdx @@ -0,0 +1,160 @@ +import { Canvas, Meta, Story, Source, ArgsTable } from '@storybook/addon-docs'; +import { Input } from "./index"; + + + +export const Template = (args) => ; + +# Input + +Cunningham provides a versatile Input component that you can use in your forms. + + + + + + + +## States + +You can use the following props to change the state of the Input component by using the `state` props. + + + + + + + + + + + + + +## Disabled + +As a regular input, you can disable it by using the `disabled` props. + + + + + + +## Icons + +You can define an icon that will appear on the left side of the input by using the `icon` props. + + + + + +You can also independently add an icon on the right side by using the `rightIcon` props. + + + + + +## Texts + +You can define a text that will appear below the input by using the `text` props. + + + + + +You can also independently add a text on the right side by using the `rightText` props. + + + + + +## Width + +By default, the input has a default width, like all inputs. But you can force it to take the full width of its container by using the `fullWidth` props. + + + + + +## Chars Counter + +You can display a counter of the number of characters entered in the input by using the `charsCounter` props. Please bare +in mind to also define `charCounterMax`. + + + + + +## Controlled / Non Controlled + +Like a native input, you can use the Input component in a controlled or non controlled way. You can see the example below +using the component in a controlled way. + + + + + +## Ref + +You can use the `ref` props to get a reference to the input element. The ref to the native input is nested inside the `input` attribute. + + + + + +## Props + +You can use all the props of the native html `` element props plus the following. + + + +## Design tokens + +Here are the custom design tokens defined by the button. + +| Token | Description | +|--------------- |----------------------------- | +| font-weight | Value font weight | +| font-size | Value font size | +| color | Value color | +| border-radius | Border radius of the input | +| border-radius--hover | Border radius of the input on mouse hover | +| border-radius--focus | Border radius of the input when focused | +| border-width | Border width of the input | +| border-color | Border color of the input | +| border-color--hover | Border color of the input on mouse hover | +| border-color--focus | Border color of the input when focus | +| border-style | Border style of the input | + +See also [Field](?path=/story/components-forms-field-doc--page) + +## Form Example + + + + + +## + + + +## + + + +## + + + +## + + + +## + + diff --git a/packages/react/src/components/Forms/Input/index.stories.tsx b/packages/react/src/components/Forms/Input/index.stories.tsx index 14846cc..a0f990e 100644 --- a/packages/react/src/components/Forms/Input/index.stories.tsx +++ b/packages/react/src/components/Forms/Input/index.stories.tsx @@ -1,17 +1,208 @@ import { ComponentMeta, ComponentStory } from "@storybook/react"; -import React from "react"; -import { Input } from "components/Forms/Input/index"; +import React, { useRef } from "react"; +import { Input, InputRefType } from "components/Forms/Input/index"; +import { Button } from "components/Button"; export default { - title: "Components/Forms (WIP)/Input", + title: "Components/Forms/Input", component: Input, } as ComponentMeta; -const Template: ComponentStory = (args) => ( - -); +const Template: ComponentStory = (args) => ; export const Default = Template.bind({}); Default.args = { defaultValue: "Hello world", + label: "Your name", +}; + +export const Success = Template.bind({}); +Success.args = { + defaultValue: "Hello world", + label: "Your name", + state: "success", + icon: person, + text: "This is an optional success message", +}; + +export const Error = Template.bind({}); +Error.args = { + defaultValue: "Hello world", + label: "Your name", + state: "error", + icon: person, + text: "This is an optional error message", +}; + +export const DisabledEmpty = Template.bind({}); +DisabledEmpty.args = { + label: "Your name", + icon: person, + disabled: true, +}; + +export const DisabledFilled = Template.bind({}); +DisabledFilled.args = { + label: "Your name", + defaultValue: "John Doe", + icon: person, + disabled: true, +}; + +export const Empty = Template.bind({}); +Empty.args = { + label: "Your email", +}; + +export const Icon = Template.bind({}); +Icon.args = { + label: "Account balance", + icon: attach_money, + defaultValue: "1000", +}; + +export const IconRight = Template.bind({}); +IconRight.args = { + label: "Account balance", + rightIcon: attach_money, + defaultValue: "1000", +}; + +export const IconBoth = Template.bind({}); +IconBoth.args = { + label: "Not a recommended use", + icon: attach_money, + rightIcon: attach_money, + defaultValue: "Is isn't recommended to use both icons", +}; + +export const OverflowingText = Template.bind({}); +OverflowingText.args = { + label: "Your name", + icon: attach_money, + defaultValue: "John Dave Mike Smith Doe Junior Senior Yoda Skywalker", +}; + +export const WithText = Template.bind({}); +WithText.args = { + defaultValue: "Hello world", + label: "Your name", + text: "This is a text, you can display anything you want here like warnings, informations or errors.", +}; + +export const WithTextRight = Template.bind({}); +WithTextRight.args = { + defaultValue: "Hello world", + label: "Your name", + rightText: "0/300", +}; + +export const WithBothTexts = Template.bind({}); +WithBothTexts.args = { + defaultValue: "Hello world", + label: "Your name", + text: "This is a text, you can display anything you want here like warnings, informations or errors.", + rightText: "0/300", +}; + +export const FullWidth = Template.bind({}); +FullWidth.args = { + defaultValue: "Hello world", + label: "Your name", + fullWidth: true, + text: "This is a text, you can display anything you want here like warnings, informations or errors.", + rightText: "0/300", +}; + +export const CharCounter = Template.bind({}); +CharCounter.args = { + defaultValue: "CEO", + label: "Job title", + text: "This is a text, you can display anything you want here like warnings, informations or errors.", + charCounter: true, + charCounterMax: 30, +}; + +export const Controlled = () => { + const [value, setValue] = React.useState("I am controlled"); + return ( +
+
+ Value: {value} +
+ setValue(e.target.value)} + /> + +
+ ); +}; + +export const NonControlled = () => { + return ; +}; + +export const WithRef = () => { + const ref = useRef(null); + return ( +
+ + +
+ ); +}; + +export const FormExample = () => { + return ( +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ apartment} + /> +
+
+ location_on} + /> +
+
+ map} + /> +
+
+
+ ); }; diff --git a/packages/react/src/components/Forms/Input/index.tsx b/packages/react/src/components/Forms/Input/index.tsx index df84fc9..1644e6d 100644 --- a/packages/react/src/components/Forms/Input/index.tsx +++ b/packages/react/src/components/Forms/Input/index.tsx @@ -1,11 +1,144 @@ -import React, { InputHTMLAttributes } from "react"; +import React, { + forwardRef, + InputHTMLAttributes, + ReactNode, + useEffect, + useImperativeHandle, + useRef, + useState, +} from "react"; +import classNames from "classnames"; +import { randomString } from "utils"; +import { Field, FieldProps } from "components/Forms/Field"; -type Props = InputHTMLAttributes; +export interface InputRefType { + input: HTMLInputElement | null; +} -export const Input = ({ className, ...props }: Props) => { - const classes = ["c__input"]; - if (className) { - classes.push(className); +type Props = InputHTMLAttributes & + FieldProps & { + label?: string; + icon?: ReactNode; + rightIcon?: ReactNode; + charCounter?: boolean; + charCounterMax?: number; + }; + +export const Input = forwardRef( + ( + { + className, + defaultValue, + label, + id, + icon, + rightIcon, + state = "default", + text, + rightText, + fullWidth, + charCounter, + charCounterMax, + ...props + }: Props, + ref + ) => { + const classes = ["c__input"]; + if (className) { + classes.push(className); + } + + const inputRef = useRef(null); + const [inputFocus, setInputFocus] = useState(false); + const [value, setValue] = useState(defaultValue || props.value || ""); + const [labelAsPlaceholder, setLabelAsPlaceholder] = useState(!value); + const idToUse = useRef(id || randomString()); + const rightTextToUse = charCounter + ? `${value.toString().length}/${charCounterMax}` + : rightText; + + const updateLabel = () => { + if (inputFocus) { + setLabelAsPlaceholder(false); + return; + } + setLabelAsPlaceholder(!value); + }; + + useEffect(() => { + updateLabel(); + }, [inputFocus, value]); + + // If the input is used as a controlled component, we need to update the local value. + useEffect(() => { + if (defaultValue !== undefined) { + return; + } + setValue(props.value || ""); + }, [props.value]); + + useImperativeHandle(ref, () => ({ + get input() { + return inputRef.current; + }, + })); + + return ( + + {/* We disabled linting for this specific line because we consider that the onClick props is only used for */} + {/* mouse users, so this do not engender any issue for accessibility. */} + {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */} +
{ + inputRef.current?.focus(); + }} + > + {!!icon && icon} +
+ { + setInputFocus(true); + props.onFocus?.(e); + }} + onBlur={(e) => { + setInputFocus(false); + props.onBlur?.(e); + }} + onChange={(e) => { + setValue(e.target.value); + props.onChange?.(e); + }} + ref={inputRef} + /> + {label && ( + + )} +
+ {!!rightIcon && rightIcon} +
+
+ ); } - return ; -}; +); diff --git a/packages/react/src/components/Forms/Input/resources/dd_1.svg b/packages/react/src/components/Forms/Input/resources/dd_1.svg new file mode 100644 index 0000000..d4e3252 --- /dev/null +++ b/packages/react/src/components/Forms/Input/resources/dd_1.svg @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/react/src/components/Forms/Input/resources/dd_2.svg b/packages/react/src/components/Forms/Input/resources/dd_2.svg new file mode 100644 index 0000000..67e27a5 --- /dev/null +++ b/packages/react/src/components/Forms/Input/resources/dd_2.svg @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/react/src/components/Forms/Input/resources/dd_3.svg b/packages/react/src/components/Forms/Input/resources/dd_3.svg new file mode 100644 index 0000000..78d052a --- /dev/null +++ b/packages/react/src/components/Forms/Input/resources/dd_3.svg @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/react/src/components/Forms/Input/resources/dd_4.svg b/packages/react/src/components/Forms/Input/resources/dd_4.svg new file mode 100644 index 0000000..a05d078 --- /dev/null +++ b/packages/react/src/components/Forms/Input/resources/dd_4.svg @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/react/src/components/Forms/Input/resources/dd_5.svg b/packages/react/src/components/Forms/Input/resources/dd_5.svg new file mode 100644 index 0000000..db65182 --- /dev/null +++ b/packages/react/src/components/Forms/Input/resources/dd_5.svg @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/react/src/components/Forms/Input/resources/dd_6.svg b/packages/react/src/components/Forms/Input/resources/dd_6.svg new file mode 100644 index 0000000..e2a6a8c --- /dev/null +++ b/packages/react/src/components/Forms/Input/resources/dd_6.svg @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/react/src/components/Forms/Input/tokens.ts b/packages/react/src/components/Forms/Input/tokens.ts new file mode 100644 index 0000000..90292c8 --- /dev/null +++ b/packages/react/src/components/Forms/Input/tokens.ts @@ -0,0 +1,15 @@ +import { DefaultTokens } from "@openfun/cunningham-tokens"; + +export const tokens = (defaults: DefaultTokens) => ({ + "font-weight": defaults.theme.font.weights.medium, + "font-size": defaults.theme.font.sizes.l, + "border-radius": "8px", + "border-radius--hover": "2px", + "border-radius--focus": "2px", + "border-width": "2px", + "border-color": defaults.theme.colors["greyscale-300"], + "border-color--hover": defaults.theme.colors["greyscale-500"], + "border-color--focus": defaults.theme.colors["primary-600"], + "border-style": "solid", + color: defaults.theme.colors["greyscale-800"], +}); diff --git a/packages/react/src/cunningham-tokens.css b/packages/react/src/cunningham-tokens.css index 912a6a4..98d5b9a 100644 --- a/packages/react/src/cunningham-tokens.css +++ b/packages/react/src/cunningham-tokens.css @@ -96,6 +96,20 @@ --c--theme--transitions--ease-out: cubic-bezier(0.33, 1, 0.68, 1); --c--theme--transitions--ease-in-out: cubic-bezier(0.65, 0, 0.35, 1); --c--theme--transitions--duration: 250ms; + --c--components--forms-input--font-weight: 400; + --c--components--forms-input--font-size: 1rem; + --c--components--forms-input--border-radius: 8px; + --c--components--forms-input--border-radius--hover: 2px; + --c--components--forms-input--border-radius--focus: 2px; + --c--components--forms-input--border-width: 2px; + --c--components--forms-input--border-color: #E7E8EA; + --c--components--forms-input--border-color--hover: #9EA3AA; + --c--components--forms-input--border-color--focus: #0556BF; + --c--components--forms-input--border-style: solid; + --c--components--forms-input--color: #303C4B; + --c--components--forms-field--width: 292px; + --c--components--forms-field--font-size: 0.6875rem; + --c--components--forms-field--color: #79818A; --c--components--button--border-radius: 8px; --c--components--button--border-radius--active: 2px; --c--components--button--medium-height: 48px; diff --git a/packages/react/src/cunningham-tokens.js b/packages/react/src/cunningham-tokens.js index b6100d3..38932f7 100644 --- a/packages/react/src/cunningham-tokens.js +++ b/packages/react/src/cunningham-tokens.js @@ -1 +1 @@ -export const tokens = {"theme":{"colors":{"primary-text":"#FFFFFF","primary-100":"#EBF2FC","primary-200":"#8CB5EA","primary-300":"#5894E1","primary-400":"#377FDB","primary-500":"#055FD2","primary-600":"#0556BF","primary-700":"#044395","primary-800":"#033474","primary-900":"#022858","secondary-text":"#555F6B","secondary-100":"#F2F7FC","secondary-200":"#EBF3FA","secondary-300":"#E2EEF8","secondary-400":"#DDEAF7","secondary-500":"#D4E5F5","secondary-600":"#C1D0DF","secondary-700":"#97A3AE","secondary-800":"#757E87","secondary-900":"#596067","greyscale-000":"#FFFFFF","greyscale-100":"#FAFAFB","greyscale-200":"#F3F4F4","greyscale-300":"#E7E8EA","greyscale-400":"#C2C6CA","greyscale-500":"#9EA3AA","greyscale-600":"#79818A","greyscale-700":"#555F6B","greyscale-800":"#303C4B","greyscale-900":"#0C1A2B","success-text":"#FFFFFF","success-100":"#EFFCD3","success-200":"#DBFAA9","success-300":"#BEF27C","success-400":"#A0E659","success-500":"#76D628","success-600":"#5AB81D","success-700":"#419A14","success-800":"#2C7C0C","success-900":"#1D6607","info-text":"#FFFFFF","info-100":"#EBF2FC","info-200":"#8CB5EA","info-300":"#5894E1","info-400":"#377FDB","info-500":"#055FD2","info-600":"#0556BF","info-700":"#044395","info-800":"#033474","info-900":"#022858","warning-text":"#FFFFFF","warning-100":"#FFF8CD","warning-200":"#FFEF9B","warning-300":"#FFE469","warning-400":"#FFDA43","warning-500":"#FFC805","warning-600":"#DBA603","warning-700":"#B78702","warning-800":"#936901","warning-900":"#7A5400","danger-text":"#FFFFFF","danger-100":"#F4B0B0","danger-200":"#EE8A8A","danger-300":"#E65454","danger-400":"#E13333","danger-500":"#DA0000","danger-600":"#C60000","danger-700":"#9B0000","danger-800":"#780000","danger-900":"#5C0000"},"font":{"sizes":{"h1":"1.75rem","h2":"1.375rem","h3":"1.125rem","h4":"0.8125rem","h5":"0.625rem","h6":"0.5rem","l":"1rem","m":"0.8125rem","s":"0.6875rem"},"weights":{"thin":100,"regular":300,"medium":400,"bold":500,"extrabold":700,"black":900},"families":{"base":"Roboto","accent":"Roboto"}},"spacings":{"xl":"4rem","l":"3rem","b":"1.625rem","s":"1rem","t":"0.5rem","st":"0.25rem"},"transitions":{"ease-in":"cubic-bezier(0.32, 0, 0.67, 0)","ease-out":"cubic-bezier(0.33, 1, 0.68, 1)","ease-in-out":"cubic-bezier(0.65, 0, 0.35, 1)","duration":"250ms"}},"components":{"button":{"border-radius":"8px","border-radius--active":"2px","medium-height":"48px","small-height":"32px","medium-font-size":"1rem","small-font-size":"0.8125rem","font-weight":400}}}; +export const tokens = {"theme":{"colors":{"primary-text":"#FFFFFF","primary-100":"#EBF2FC","primary-200":"#8CB5EA","primary-300":"#5894E1","primary-400":"#377FDB","primary-500":"#055FD2","primary-600":"#0556BF","primary-700":"#044395","primary-800":"#033474","primary-900":"#022858","secondary-text":"#555F6B","secondary-100":"#F2F7FC","secondary-200":"#EBF3FA","secondary-300":"#E2EEF8","secondary-400":"#DDEAF7","secondary-500":"#D4E5F5","secondary-600":"#C1D0DF","secondary-700":"#97A3AE","secondary-800":"#757E87","secondary-900":"#596067","greyscale-000":"#FFFFFF","greyscale-100":"#FAFAFB","greyscale-200":"#F3F4F4","greyscale-300":"#E7E8EA","greyscale-400":"#C2C6CA","greyscale-500":"#9EA3AA","greyscale-600":"#79818A","greyscale-700":"#555F6B","greyscale-800":"#303C4B","greyscale-900":"#0C1A2B","success-text":"#FFFFFF","success-100":"#EFFCD3","success-200":"#DBFAA9","success-300":"#BEF27C","success-400":"#A0E659","success-500":"#76D628","success-600":"#5AB81D","success-700":"#419A14","success-800":"#2C7C0C","success-900":"#1D6607","info-text":"#FFFFFF","info-100":"#EBF2FC","info-200":"#8CB5EA","info-300":"#5894E1","info-400":"#377FDB","info-500":"#055FD2","info-600":"#0556BF","info-700":"#044395","info-800":"#033474","info-900":"#022858","warning-text":"#FFFFFF","warning-100":"#FFF8CD","warning-200":"#FFEF9B","warning-300":"#FFE469","warning-400":"#FFDA43","warning-500":"#FFC805","warning-600":"#DBA603","warning-700":"#B78702","warning-800":"#936901","warning-900":"#7A5400","danger-text":"#FFFFFF","danger-100":"#F4B0B0","danger-200":"#EE8A8A","danger-300":"#E65454","danger-400":"#E13333","danger-500":"#DA0000","danger-600":"#C60000","danger-700":"#9B0000","danger-800":"#780000","danger-900":"#5C0000"},"font":{"sizes":{"h1":"1.75rem","h2":"1.375rem","h3":"1.125rem","h4":"0.8125rem","h5":"0.625rem","h6":"0.5rem","l":"1rem","m":"0.8125rem","s":"0.6875rem"},"weights":{"thin":100,"regular":300,"medium":400,"bold":500,"extrabold":700,"black":900},"families":{"base":"Roboto","accent":"Roboto"}},"spacings":{"xl":"4rem","l":"3rem","b":"1.625rem","s":"1rem","t":"0.5rem","st":"0.25rem"},"transitions":{"ease-in":"cubic-bezier(0.32, 0, 0.67, 0)","ease-out":"cubic-bezier(0.33, 1, 0.68, 1)","ease-in-out":"cubic-bezier(0.65, 0, 0.35, 1)","duration":"250ms"}},"components":{"forms-input":{"font-weight":400,"font-size":"1rem","border-radius":"8px","border-radius--hover":"2px","border-radius--focus":"2px","border-width":"2px","border-color":"#E7E8EA","border-color--hover":"#9EA3AA","border-color--focus":"#0556BF","border-style":"solid","color":"#303C4B"},"forms-field":{"width":"292px","font-size":"0.6875rem","color":"#79818A"},"button":{"border-radius":"8px","border-radius--active":"2px","medium-height":"48px","small-height":"32px","medium-font-size":"1rem","small-font-size":"0.8125rem","font-weight":400}}}; diff --git a/packages/react/src/cunningham-tokens.ts b/packages/react/src/cunningham-tokens.ts index b6100d3..38932f7 100644 --- a/packages/react/src/cunningham-tokens.ts +++ b/packages/react/src/cunningham-tokens.ts @@ -1 +1 @@ -export const tokens = {"theme":{"colors":{"primary-text":"#FFFFFF","primary-100":"#EBF2FC","primary-200":"#8CB5EA","primary-300":"#5894E1","primary-400":"#377FDB","primary-500":"#055FD2","primary-600":"#0556BF","primary-700":"#044395","primary-800":"#033474","primary-900":"#022858","secondary-text":"#555F6B","secondary-100":"#F2F7FC","secondary-200":"#EBF3FA","secondary-300":"#E2EEF8","secondary-400":"#DDEAF7","secondary-500":"#D4E5F5","secondary-600":"#C1D0DF","secondary-700":"#97A3AE","secondary-800":"#757E87","secondary-900":"#596067","greyscale-000":"#FFFFFF","greyscale-100":"#FAFAFB","greyscale-200":"#F3F4F4","greyscale-300":"#E7E8EA","greyscale-400":"#C2C6CA","greyscale-500":"#9EA3AA","greyscale-600":"#79818A","greyscale-700":"#555F6B","greyscale-800":"#303C4B","greyscale-900":"#0C1A2B","success-text":"#FFFFFF","success-100":"#EFFCD3","success-200":"#DBFAA9","success-300":"#BEF27C","success-400":"#A0E659","success-500":"#76D628","success-600":"#5AB81D","success-700":"#419A14","success-800":"#2C7C0C","success-900":"#1D6607","info-text":"#FFFFFF","info-100":"#EBF2FC","info-200":"#8CB5EA","info-300":"#5894E1","info-400":"#377FDB","info-500":"#055FD2","info-600":"#0556BF","info-700":"#044395","info-800":"#033474","info-900":"#022858","warning-text":"#FFFFFF","warning-100":"#FFF8CD","warning-200":"#FFEF9B","warning-300":"#FFE469","warning-400":"#FFDA43","warning-500":"#FFC805","warning-600":"#DBA603","warning-700":"#B78702","warning-800":"#936901","warning-900":"#7A5400","danger-text":"#FFFFFF","danger-100":"#F4B0B0","danger-200":"#EE8A8A","danger-300":"#E65454","danger-400":"#E13333","danger-500":"#DA0000","danger-600":"#C60000","danger-700":"#9B0000","danger-800":"#780000","danger-900":"#5C0000"},"font":{"sizes":{"h1":"1.75rem","h2":"1.375rem","h3":"1.125rem","h4":"0.8125rem","h5":"0.625rem","h6":"0.5rem","l":"1rem","m":"0.8125rem","s":"0.6875rem"},"weights":{"thin":100,"regular":300,"medium":400,"bold":500,"extrabold":700,"black":900},"families":{"base":"Roboto","accent":"Roboto"}},"spacings":{"xl":"4rem","l":"3rem","b":"1.625rem","s":"1rem","t":"0.5rem","st":"0.25rem"},"transitions":{"ease-in":"cubic-bezier(0.32, 0, 0.67, 0)","ease-out":"cubic-bezier(0.33, 1, 0.68, 1)","ease-in-out":"cubic-bezier(0.65, 0, 0.35, 1)","duration":"250ms"}},"components":{"button":{"border-radius":"8px","border-radius--active":"2px","medium-height":"48px","small-height":"32px","medium-font-size":"1rem","small-font-size":"0.8125rem","font-weight":400}}}; +export const tokens = {"theme":{"colors":{"primary-text":"#FFFFFF","primary-100":"#EBF2FC","primary-200":"#8CB5EA","primary-300":"#5894E1","primary-400":"#377FDB","primary-500":"#055FD2","primary-600":"#0556BF","primary-700":"#044395","primary-800":"#033474","primary-900":"#022858","secondary-text":"#555F6B","secondary-100":"#F2F7FC","secondary-200":"#EBF3FA","secondary-300":"#E2EEF8","secondary-400":"#DDEAF7","secondary-500":"#D4E5F5","secondary-600":"#C1D0DF","secondary-700":"#97A3AE","secondary-800":"#757E87","secondary-900":"#596067","greyscale-000":"#FFFFFF","greyscale-100":"#FAFAFB","greyscale-200":"#F3F4F4","greyscale-300":"#E7E8EA","greyscale-400":"#C2C6CA","greyscale-500":"#9EA3AA","greyscale-600":"#79818A","greyscale-700":"#555F6B","greyscale-800":"#303C4B","greyscale-900":"#0C1A2B","success-text":"#FFFFFF","success-100":"#EFFCD3","success-200":"#DBFAA9","success-300":"#BEF27C","success-400":"#A0E659","success-500":"#76D628","success-600":"#5AB81D","success-700":"#419A14","success-800":"#2C7C0C","success-900":"#1D6607","info-text":"#FFFFFF","info-100":"#EBF2FC","info-200":"#8CB5EA","info-300":"#5894E1","info-400":"#377FDB","info-500":"#055FD2","info-600":"#0556BF","info-700":"#044395","info-800":"#033474","info-900":"#022858","warning-text":"#FFFFFF","warning-100":"#FFF8CD","warning-200":"#FFEF9B","warning-300":"#FFE469","warning-400":"#FFDA43","warning-500":"#FFC805","warning-600":"#DBA603","warning-700":"#B78702","warning-800":"#936901","warning-900":"#7A5400","danger-text":"#FFFFFF","danger-100":"#F4B0B0","danger-200":"#EE8A8A","danger-300":"#E65454","danger-400":"#E13333","danger-500":"#DA0000","danger-600":"#C60000","danger-700":"#9B0000","danger-800":"#780000","danger-900":"#5C0000"},"font":{"sizes":{"h1":"1.75rem","h2":"1.375rem","h3":"1.125rem","h4":"0.8125rem","h5":"0.625rem","h6":"0.5rem","l":"1rem","m":"0.8125rem","s":"0.6875rem"},"weights":{"thin":100,"regular":300,"medium":400,"bold":500,"extrabold":700,"black":900},"families":{"base":"Roboto","accent":"Roboto"}},"spacings":{"xl":"4rem","l":"3rem","b":"1.625rem","s":"1rem","t":"0.5rem","st":"0.25rem"},"transitions":{"ease-in":"cubic-bezier(0.32, 0, 0.67, 0)","ease-out":"cubic-bezier(0.33, 1, 0.68, 1)","ease-in-out":"cubic-bezier(0.65, 0, 0.35, 1)","duration":"250ms"}},"components":{"forms-input":{"font-weight":400,"font-size":"1rem","border-radius":"8px","border-radius--hover":"2px","border-radius--focus":"2px","border-width":"2px","border-color":"#E7E8EA","border-color--hover":"#9EA3AA","border-color--focus":"#0556BF","border-style":"solid","color":"#303C4B"},"forms-field":{"width":"292px","font-size":"0.6875rem","color":"#79818A"},"button":{"border-radius":"8px","border-radius--active":"2px","medium-height":"48px","small-height":"32px","medium-font-size":"1rem","small-font-size":"0.8125rem","font-weight":400}}}; diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index 5ae814a..f090e08 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -4,6 +4,7 @@ export * from "./components/Button"; export * from "./components/DataGrid"; export * from "./components/DataGrid/SimpleDataGrid"; export * from "./components/Forms/Field"; +export * from "./components/Forms/Input"; export * from "./components/Loader"; export * from "./components/Pagination"; export * from "./components/Provider"; diff --git a/packages/react/src/utils/index.ts b/packages/react/src/utils/index.ts index f7dc4fe..63e217b 100644 --- a/packages/react/src/utils/index.ts +++ b/packages/react/src/utils/index.ts @@ -3,3 +3,12 @@ export const noop = () => undefined; export function sleep(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); } + +export function randomString(length: number = 8): string { + const chars = + "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + let result = ""; + for (let i = length; i > 0; --i) + result += chars[Math.floor(Math.random() * chars.length)]; + return result; +}