-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the text-field component (#58)
# Pull Request ## π Description <!--- Provide some background and a description of your work. --> Added the text-field foundation component. ### π« Issues <!--- List and link relevant issues here using the keyword "closes" if this PR will close an issue, eg. closes #411 --> - Continues work on #31 ## β Checklist ### General <!--- Review the list and put an x in the boxes that apply. --> - [x] I have added tests for my changes. - [x] I have tested my changes. - [x] I have updated the project documentation to reflect my changes. ## β Next Steps <!--- If there is relevant follow-up work to this PR, please list any existing issues or provide brief descriptions of what you would like to do next. --> - Continue adding foundation components
- Loading branch information
Showing
15 changed files
with
462 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@microsoft-fast-cli-e5b24068-2260-4e69-a6c4-9fa4ddf7b932.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "none", | ||
"comment": "Added the text-field component", | ||
"packageName": "@microsoft/fast-cli", | ||
"email": "7559015+janechu@users.noreply.github.com", | ||
"dependentChangeType": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,6 @@ export const availableTemplates = [ | |
"progress-ring", | ||
"search", | ||
"switch", | ||
"text-field", | ||
"toolbar", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Description | ||
|
||
This template is used as a text-field component template from which a user can modify without having to do the initial scaffolding. |
33 changes: 33 additions & 0 deletions
33
packages/fast-cli/src/components/text-field/template.pw.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { expect, test } from "@playwright/test"; | ||
import { execSync } from "child_process"; | ||
import { | ||
expectedGeneratedComponentTemplateFiles, | ||
setupComponent, | ||
teardown, | ||
getGeneratedComponentFiles, | ||
getTempDir, | ||
getTempComponentDir, | ||
} from "../../test/helpers.js"; | ||
|
||
const uuid: string = "text-field"; | ||
const tempDir: string = getTempDir(uuid); | ||
const tempComponentDir: string = getTempComponentDir(uuid); | ||
|
||
test.describe(`CLI add-foundation-component ${uuid}`, () => { | ||
test.beforeAll(() => { | ||
setupComponent(uuid, tempDir, tempComponentDir); | ||
}); | ||
test.afterAll(() => { | ||
teardown(tempDir, tempComponentDir); | ||
}); | ||
test("should copy files from the template", () => { | ||
expect(getGeneratedComponentFiles(tempDir)).toEqual(expectedGeneratedComponentTemplateFiles); | ||
}); | ||
test("should be able to run the build", () => { | ||
expect( | ||
() => { | ||
execSync(`cd ${tempDir} && npm run build`); | ||
} | ||
).not.toThrow(); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/fast-cli/src/components/text-field/template/README.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { ComponentTemplateConfig } from "../../../utilities/template"; | ||
|
||
export default (config: ComponentTemplateConfig): string => ` | ||
# ${config.className} | ||
An implementation of a [text field](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input/text) as a form-connected web-component. | ||
For more information on the building blocks used to create this component, please refer to https://www.fast.design/docs/components/text-field`; |
14 changes: 14 additions & 0 deletions
14
packages/fast-cli/src/components/text-field/template/component.definition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { ComponentTemplateConfig } from "../../../utilities/template"; | ||
|
||
export default (config: ComponentTemplateConfig): string => | ||
`import { template } from "./${config.tagName}.template.js"; | ||
import { styles } from "./${config.tagName}.styles.js"; | ||
export const definition = { | ||
baseName: "${config.tagName}", | ||
template, | ||
styles, | ||
shadowOptions: { | ||
delegatesFocus: true, | ||
}, | ||
};`; |
25 changes: 25 additions & 0 deletions
25
packages/fast-cli/src/components/text-field/template/component.pw.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { ComponentTemplateConfig } from "../../../utilities/template"; | ||
|
||
export default (config: ComponentTemplateConfig): string => ` | ||
import { expect, test } from "@playwright/test"; | ||
import { fixtureURL } from "@microsoft/fast-cli/dist/esm/utilities/playwright.js"; | ||
test.describe("${config.tagName}", () => { | ||
const fixture = fixtureURL("${config.tagName}"); | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto(fixture); | ||
}); | ||
test("should load the fixture URL", async ({ page }) => { | ||
const pageUrl = page.url(); | ||
expect(pageUrl).toBe(\`http://localhost:3000/\${fixture}\`); | ||
}); | ||
test("should contain the component in the URL", async ({ page }) => { | ||
const element = page.locator("${config.tagName}"); | ||
await expect(element).not.toBeNull(); | ||
}); | ||
}); | ||
` |
12 changes: 12 additions & 0 deletions
12
packages/fast-cli/src/components/text-field/template/component.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { ComponentTemplateConfig } from "../../../utilities/template"; | ||
|
||
export default (config: ComponentTemplateConfig): string => ` | ||
import Template from "./fixtures/base.html"; | ||
import "./define.js"; | ||
export default { | ||
title: "${config.tagName}", | ||
}; | ||
export const ${config.className} = () => Template; | ||
`; |
183 changes: 183 additions & 0 deletions
183
packages/fast-cli/src/components/text-field/template/component.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
import type { ComponentTemplateConfig } from "../../../utilities/template"; | ||
|
||
export default (config: ComponentTemplateConfig): string => | ||
`import { css, ElementStyles } from "@microsoft/fast-element"; | ||
import { | ||
disabledCursor, | ||
display, | ||
focusVisible, | ||
forcedColorsStylesheetBehavior, | ||
FoundationElementTemplate, | ||
TextFieldOptions, | ||
} from "@microsoft/fast-foundation"; | ||
import { SystemColors } from "@microsoft/fast-web-utilities"; | ||
import { | ||
accentFillActive, | ||
accentFillHover, | ||
accentFillRest, | ||
bodyFont, | ||
controlCornerRadius, | ||
designUnit, | ||
disabledOpacity, | ||
focusStrokeOuter, | ||
focusStrokeWidth, | ||
heightNumber, | ||
neutralFillHover, | ||
neutralFillInputHover, | ||
neutralFillInputRest, | ||
neutralFillRest, | ||
neutralForegroundRest, | ||
neutralStrokeRest, | ||
strokeWidth, | ||
typeRampBaseFontSize, | ||
typeRampBaseLineHeight, | ||
} from "@microsoft/adaptive-ui"; | ||
/** | ||
* Styles for \${config.className} | ||
* @public | ||
*/ | ||
export const styles: FoundationElementTemplate<ElementStyles> = ( | ||
context, | ||
definition | ||
) => | ||
css\` | ||
\${display("inline-block")} :host { | ||
font-family: \${bodyFont}; | ||
outline: none; | ||
user-select: none; | ||
} | ||
.root { | ||
box-sizing: border-box; | ||
position: relative; | ||
display: flex; | ||
flex-direction: row; | ||
color: \${neutralForegroundRest}; | ||
background: \${neutralFillInputRest}; | ||
border-radius: calc(\${controlCornerRadius} * 1px); | ||
border: calc(\${strokeWidth} * 1px) solid \${accentFillRest}; | ||
height: calc(\${heightNumber} * 1px); | ||
align-items: baseline; | ||
} | ||
.control { | ||
-webkit-appearance: none; | ||
font: inherit; | ||
background: transparent; | ||
border: 0; | ||
color: inherit; | ||
height: calc(100% - 4px); | ||
width: 100%; | ||
margin-top: auto; | ||
margin-bottom: auto; | ||
border: none; | ||
padding: 0 calc(\${designUnit} * 2px + 1px); | ||
font-size: \${typeRampBaseFontSize}; | ||
line-height: \${typeRampBaseLineHeight}; | ||
} | ||
.control:hover, | ||
.control:\${focusVisible}, | ||
.control:disabled, | ||
.control:active { | ||
outline: none; | ||
} | ||
.label { | ||
display: block; | ||
color: \${neutralForegroundRest}; | ||
cursor: pointer; | ||
font-size: \${typeRampBaseFontSize}; | ||
line-height: \${typeRampBaseLineHeight}; | ||
margin-bottom: 4px; | ||
} | ||
.label__hidden { | ||
display: none; | ||
visibility: hidden; | ||
} | ||
.start, | ||
.control, | ||
.end { | ||
align-self: center; | ||
} | ||
.start, | ||
.end { | ||
display: flex; | ||
margin: auto; | ||
fill: currentcolor; | ||
} | ||
::slotted(svg) { | ||
/* TODO: adaptive typography https://github.com/microsoft/fast/issues/2432 */ | ||
width: 16px; | ||
height: 16px; | ||
} | ||
.start { | ||
margin-inline-start: 11px; | ||
} | ||
.end { | ||
margin-inline-end: 11px; | ||
} | ||
:host(:hover:not([disabled])) .root { | ||
background: \${neutralFillInputHover}; | ||
border-color: \${accentFillHover}; | ||
} | ||
:host(:active:not([disabled])) .root { | ||
background: \${neutralFillInputHover}; | ||
border-color: \${accentFillActive}; | ||
} | ||
:host(:focus-within:not([disabled])) .root { | ||
border-color: \${focusStrokeOuter}; | ||
box-shadow: 0 0 0 calc(\${focusStrokeWidth} * 1px) \${focusStrokeOuter} inset; | ||
} | ||
:host([appearance="filled"]) .root { | ||
background: \${neutralFillRest}; | ||
} | ||
:host([appearance="filled"]:hover:not([disabled])) .root { | ||
background: \${neutralFillHover}; | ||
} | ||
:host([disabled]) .label, | ||
:host([readonly]) .label, | ||
:host([readonly]) .control, | ||
:host([disabled]) .control { | ||
cursor: \${disabledCursor}; | ||
} | ||
:host([disabled]) { | ||
opacity: \${disabledOpacity}; | ||
} | ||
:host([disabled]) .control { | ||
border-color: \${neutralStrokeRest}; | ||
} | ||
\`.withBehaviors( | ||
forcedColorsStylesheetBehavior( | ||
css\` | ||
.root, | ||
:host([appearance="filled"]) .root { | ||
forced-color-adjust: none; | ||
background: \${SystemColors.Field}; | ||
border-color: \${SystemColors.FieldText}; | ||
} | ||
:host(:hover:not([disabled])) .root, | ||
:host([appearance="filled"]:hover:not([disabled])) .root, | ||
:host([appearance="filled"]:hover) .root { | ||
background: \${SystemColors.Field}; | ||
border-color: \${SystemColors.Highlight}; | ||
} | ||
.start, | ||
.end { | ||
fill: currentcolor; | ||
} | ||
:host([disabled]) { | ||
opacity: 1; | ||
} | ||
:host([disabled]) .root, | ||
:host([appearance="filled"]:hover[disabled]) .root { | ||
border-color: \${SystemColors.GrayText}; | ||
background: \${SystemColors.Field}; | ||
} | ||
:host(:focus-within:enabled) .root { | ||
border-color: \${SystemColors.Highlight}; | ||
box-shadow: 0 0 0 1px \${SystemColors.Highlight} inset; | ||
} | ||
input::placeholder { | ||
color: \${SystemColors.GrayText}; | ||
} | ||
\` | ||
) | ||
);`; |
12 changes: 12 additions & 0 deletions
12
packages/fast-cli/src/components/text-field/template/component.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { ComponentTemplateConfig } from "../../../utilities/template"; | ||
|
||
export default (config: ComponentTemplateConfig): string => ` | ||
import { TextField, textFieldTemplate, FoundationElementTemplate } from "@microsoft/fast-foundation"; | ||
import type { ViewTemplate } from "@microsoft/fast-element"; | ||
/** | ||
* The template for ${config.className} component. | ||
* @public | ||
*/ | ||
export const template: FoundationElementTemplate<ViewTemplate<TextField>> = textFieldTemplate; | ||
`; |
26 changes: 26 additions & 0 deletions
26
packages/fast-cli/src/components/text-field/template/component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { ComponentTemplateConfig } from "../../../utilities/template"; | ||
|
||
export default (config: ComponentTemplateConfig): string => | ||
`import { attr } from "@microsoft/fast-element"; | ||
import { TextField } from "@microsoft/fast-foundation"; | ||
/** | ||
* Text field appearances | ||
* @public | ||
*/ | ||
export type TextFieldAppearance = "filled" | "outline"; | ||
/** | ||
* A class derived from the TextField foundation component | ||
*/ | ||
export class ${config.className} extends TextField { | ||
/** | ||
* The appearance of the element. | ||
* | ||
* @public | ||
* @remarks | ||
* HTML Attribute: appearance | ||
*/ | ||
@attr | ||
public appearance: TextFieldAppearance = "outline"; | ||
};` |
7 changes: 7 additions & 0 deletions
7
packages/fast-cli/src/components/text-field/template/define.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { ComponentTemplateConfig } from "../../../utilities/template"; | ||
|
||
export default (config: ComponentTemplateConfig): string => | ||
`import { ${config.className} } from "./${config.tagName}.js"; | ||
import { definition } from "./${config.tagName}.definition.js"; | ||
${config.className}.compose(definition);`; |
8 changes: 8 additions & 0 deletions
8
packages/fast-cli/src/components/text-field/template/fast.add-component.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"packageJson": { | ||
"dependencies": { | ||
"@microsoft/adaptive-ui": "../adaptive-ui", | ||
"@microsoft/fast-foundation": "^2.46.2" | ||
} | ||
} | ||
} |
Oops, something went wrong.