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

Fork number-field and text-field templates #2495

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
mollykreis marked this conversation as resolved.
Show resolved Hide resolved
"type": "patch",
"comment": "Fork number-field and text-field templates",
"packageName": "@ni/nimble-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
4 changes: 2 additions & 2 deletions packages/nimble-components/src/number-field/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { attr, html } from '@microsoft/fast-element';
import {
DesignSystem,
NumberField as FoundationNumberField,
NumberFieldOptions,
numberFieldTemplate as template
NumberFieldOptions
} from '@microsoft/fast-foundation';
import { styles } from './styles';
import { NumberFieldAppearance } from './types';
Expand All @@ -17,6 +16,7 @@ import {
numericDecrementLabel,
numericIncrementLabel
} from '../label-provider/core/label-tokens';
import { template } from './template';

declare global {
interface HTMLElementTagNameMap {
Expand Down
102 changes: 102 additions & 0 deletions packages/nimble-components/src/number-field/template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { html, ref, slotted, when } from '@microsoft/fast-element';
import type { ViewTemplate } from '@microsoft/fast-element';
import {
endSlotTemplate,
FoundationElementTemplate,
NumberFieldOptions,
startSlotTemplate
} from '@microsoft/fast-foundation';
import type { NumberField } from '.';

/**
* The template for the {@link @microsoft/fast-foundation#(NumberField:class)} component.
* @public
*/
export const template: FoundationElementTemplate<
ViewTemplate<NumberField>,
NumberFieldOptions
> = (context, definition) => html`
<template class="${x => (x.readOnly ? 'readonly' : '')}">
<label
part="label"
for="control"
class="${x => (x.defaultSlottedNodes?.length
? 'label'
: 'label label__hidden')}"
>
<slot ${slotted('defaultSlottedNodes')}></slot>
</label>
<div class="root" part="root">
${startSlotTemplate(context, definition)}
<input
class="control"
part="control"
id="control"
@input="${x => x.handleTextInput()}"
@change="${x => x.handleChange()}"
@keydown="${(x, c) => x.handleKeyDown(c.event as KeyboardEvent)}"
@blur="${x => x.handleBlur()}"
?autofocus="${x => x.autofocus}"
?disabled="${x => x.disabled}"
list="${x => x.list}"
maxlength="${x => x.maxlength}"
minlength="${x => x.minlength}"
placeholder="${x => x.placeholder}"
?readonly="${x => x.readOnly}"
?required="${x => x.required}"
size="${x => x.size}"
type="text"
inputmode="numeric"
min="${x => x.min}"
max="${x => x.max}"
step="${x => x.step}"
aria-atomic="${x => x.ariaAtomic}"
aria-busy="${x => x.ariaBusy}"
aria-controls="${x => x.ariaControls}"
aria-current="${x => x.ariaCurrent}"
aria-describedby="${x => x.ariaDescribedby}"
aria-details="${x => x.ariaDetails}"
aria-disabled="${x => x.ariaDisabled}"
aria-errormessage="${x => x.ariaErrormessage}"
aria-flowto="${x => x.ariaFlowto}"
aria-haspopup="${x => x.ariaHaspopup}"
aria-hidden="${x => x.ariaHidden}"
aria-invalid="${x => x.ariaInvalid}"
aria-keyshortcuts="${x => x.ariaKeyshortcuts}"
aria-label="${x => x.ariaLabel}"
aria-labelledby="${x => x.ariaLabelledby}"
aria-live="${x => x.ariaLive}"
aria-owns="${x => x.ariaOwns}"
aria-relevant="${x => x.ariaRelevant}"
aria-roledescription="${x => x.ariaRoledescription}"
${ref('control')}
/>
${when(
x => !x.hideStep && !x.readOnly && !x.disabled,
html<NumberField>`
<div class="controls" part="controls">
<div
class="step-up"
part="step-up"
@click="${x => x.stepUp()}"
>
<slot name="step-up-glyph">
${definition.stepUpGlyph || ''}
</slot>
</div>
<div
class="step-down"
part="step-down"
@click="${x => x.stepDown()}"
>
<slot name="step-down-glyph">
${definition.stepDownGlyph || ''}
</slot>
</div>
</div>
`
)}
${endSlotTemplate(context, definition)}
</div>
</template>
`;
Loading
Loading