Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web components - Input: Create unit tests #79

Open
wants to merge 7 commits into
base: al-text-input-alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,440 changes: 7,144 additions & 296 deletions custom-elements.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import js from "@eslint/js";
import eslintConfigPrettierRecommended from "eslint-config-prettier";
import vitest from "@vitest/eslint-plugin";

export default [js.configs.recommended, eslintConfigPrettierRecommended];
export default [js.configs.recommended, eslintConfigPrettierRecommended, vitest];
199 changes: 199 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@storybook/theming": "^8.2.9",
"@storybook/web-components": "^8.2.9",
"@storybook/web-components-vite": "^8.2.9",
"@vitest/eslint-plugin": "^1.1.7",
"@vitest/ui": "^1.6.0",
"axe-playwright": "^2.0.2",
"concurrently": "^8.2.2",
Expand Down
4 changes: 3 additions & 1 deletion src/components/usa-text-input/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LitElement, css, html } from "lit";
import { LitElement, html } from "lit";
import styles from "./usa-text-input.css.js";

/**
Expand All @@ -9,6 +9,8 @@ import styles from "./usa-text-input.css.js";
* @cssprop --theme-input-line-height - Sets the line-height of input element
* @cssprop --theme-input-max-width - Sets the max width of the input element
* @cssprop --theme-input-state-border-width - Sets the border width of error and success states.
*
* @prop State - Controls state variants
*
* @tagname usa-text-input
*/
Expand Down
18 changes: 15 additions & 3 deletions src/components/usa-text-input/text-input.stories.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import "./index";

import { html } from "lit";
import { html, nothing } from "lit";

export default {
title: "Components/Text input",
component: "usa-text-input",
render: () => html`
<usa-text-input>
argTypes: {
state: {
control: { type: "radio" },
options: ["Default", "success", "error", "disabled"],
table: {
defaultValue: { summary: "Default" },
},
},
},
args: {
state: "Default",
},
render: ({ state }) => html`
<usa-text-input state=${state == "Default" ? nothing : state}>
<label for="input-type-text">Text input label</label>
<input id="input-type-text" name="input-type-text" />
</usa-text-input>
Expand Down
47 changes: 45 additions & 2 deletions src/components/usa-text-input/usa-text-input.css.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ export default css`
--theme-input-line-height: 1.3;
--theme-input-max-width: 30rem;
--theme-input-state-border-width: var(--usa-system-unit-05);
--theme-input-state-border-negative-margin: calc(
var(--usa-system-unit-1) - vcar(--theme-input-state-border-width)
);

.usa-input {
input {
box-sizing: border-box;
background: var(--usa-theme-page-background-color);
border-width: 1px;
Expand Down Expand Up @@ -44,7 +47,13 @@ export default css`
outline-offset: var(--usa-theme-focus-offset);
}

.usa-label {
input:disabled {
background-color: var(--usa-theme-color-disabled-lighter);
color: var(--usa-theme-color-disabled-dark);
cursor: not-allowed;
}

label {
color: var(--usa-theme-text-color);
font-family:
Source Sans Pro Web,
Expand All @@ -61,4 +70,38 @@ export default css`
max-width: var(--usa-system-unit-mobile-lg);
}
}

:host([state=success]),
:host([state=error]) {
input {
border-width: var(--theme-input-state-border-width);
padding-top: var(--theme-input-state-border-negative-margin);
padding-bottom: var(--theme-input-state-border-negative-margin);
}
}

:host([state=success]) {
input {
border-color: var(--usa-system-color-green-cool-40v);
}
}

:host([state=error]) {
input {
border-color: var(--usa-theme-color-error-dark);
}

label {
font-weight: 700;
margin-top: 0;
}
}

:host([state=disabled]) {
input {
background-color: var(--usa-theme-color-disabled-lighter);
color: var(--usa-theme-color-disabled-dark);
cursor: not-allowed;
}
}
`;
Loading
Loading