Skip to content

Commit

Permalink
feature: document textfield native pickers usage (#809)
Browse files Browse the repository at this point in the history
* feature: document textfield native pickers usage

* implement showpicker

* Update libs/web-components/textfield/README.md

Co-authored-by: dorsaf frigui <[email protected]>

Co-authored-by: dorsaf frigui <[email protected]>
  • Loading branch information
Pi5rr5 and dorsaffrigui authored Aug 3, 2022
1 parent 43c641b commit 3f3ddf4
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
12 changes: 12 additions & 0 deletions libs/web-components/textfield/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,15 @@ import '@finastra/textfield';
<fds-textfield label="Field me in">
</fds-textfield>
```

### Native pickers

Date pickers and Time pickers allow selecting a value from a standard format.

The **Textfield** support date `type="date"`, time `type="time"` and date&time `type="datetime-local"` pickers. See [MDN web docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date) for more information about the different `input` types.

#### Example

```html
<fds-textfield type="date" iconTrailing="calendar_today"></fds-textfield>
```
8 changes: 8 additions & 0 deletions libs/web-components/textfield/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
<fds-textfield label="Label" showActionButton placeholder="Placeholder" icon="lock_outline" disabled>
<fds-icon-button slot="actionButton" icon="visibility_off" onclick="myFunction(this)"></fds-icon-button>
</fds-textfield>


<fds-textfield type="date" iconTrailing="calendar_today" dense></fds-textfield>

<fds-textfield type="datetime-local" iconTrailing="calendar_today" dense></fds-textfield>

<fds-textfield type="date" iconTrailing="calendar_today" dense disabled></fds-textfield>

</div>

<script>
Expand Down
12 changes: 11 additions & 1 deletion libs/web-components/textfield/src/textfield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Textfield extends TextFieldBase {

return html`
${!this.labelInside ? this.renderLabelOutside() : ''}
<label class="mdc-text-field ${classMap(classes)}">
<label class="mdc-text-field ${classMap(classes)}" @click="${this._handleClick}">
${this.renderRipple()}
${this.renderOutline()}
${this.renderLeadingIcon()}
Expand All @@ -71,6 +71,16 @@ export class Textfield extends TextFieldBase {
`;
}

protected _handleClick(e) {
if (!this.disabled && (this.type === "date" || "datetime-local" || "month" || "week" || "time")) {
e.path.forEach(p => {
if (p.nodeName === "INPUT") {
p.showPicker();
}
});
}
}

protected renderTrailingIcon(): TemplateResult | string {
return this.showActionButton
? html`
Expand Down
45 changes: 43 additions & 2 deletions libs/web-components/textfield/stories/textfield.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export default {
url: 'https://www.figma.com/file/E1Mb1556RT3HbAUVu2Q0LV/Finastra-design-system?node-id=105319%3A31992'
},
cssprops
},
}
} as Meta;

const Template: Story<Textfield> = ({ label, placeholder, icon, disabled, dense, required, iconTrailing, helper, labelInside}) => {
return html`<fds-textfield label=${label} placeholder=${placeholder} icon=${icon} ?disabled=${disabled} ?dense=${dense} ?required=${required} iconTrailing=${iconTrailing} helper=${helper} ?labelInside=${labelInside}></fds-textfield>`;
};

const ValidationTemplate: Story<Textfield> = ({ label, icon, helper, type, validationMessage,pattern}) => {
const ValidationTemplate: Story<Textfield> = ({ label, icon, helper, type, validationMessage, pattern}) => {
return html`<fds-textfield label=${label} icon=${icon} type=${type} validationMessage=${validationMessage} ?helper=${helper} pattern=${pattern}></fds-textfield>`;
};

Expand All @@ -37,6 +37,10 @@ const ActionButtonTemplate: Story<Textfield> = ({ label, icon, type, helper, sho
`;
};

const NativeDatePickerTemplate: Story<Textfield> = ({ value, label, placeholder, icon, type, disabled, dense, required, iconTrailing, helper, labelInside}) => {
return html`<fds-textfield value=${value} label=${label} placeholder=${placeholder} icon=${icon} type=${type} ?disabled=${disabled} ?dense=${dense} ?required=${required} iconTrailing=${iconTrailing} helper=${helper} ?labelInside=${labelInside}></fds-textfield>`;
};

export const Default: Story<Textfield> = Template.bind({});
Default.args = {
label: 'Label',
Expand Down Expand Up @@ -108,3 +112,40 @@ LabelInside.args = {
icon: 'person_outline',
helper: "Helper text"
}

export const NativeDatePicker: Story<Textfield> = NativeDatePickerTemplate.bind({});
NativeDatePicker.args = {
dense: true,
type: 'date',
icon: 'calendar_today',
label: 'Datepicker',
value: '2017-05-24'
};

export const NativeTimePicker: Story<Textfield> = NativeDatePickerTemplate.bind({});
NativeTimePicker.args = {
dense: true,
type: 'time',
icon: 'schedule',
label: 'Timepicker',
value: '07:30'
};

export const NativeDateTimePicker: Story<Textfield> = NativeDatePickerTemplate.bind({});
NativeDateTimePicker.args = {
dense: true,
type: 'datetime-local',
icon: 'calendar_today',
label: 'Datepicker',
value: '2017-05-24T10:30'
};

export const NativeDatePickerDisabled: Story<Textfield> = NativeDatePickerTemplate.bind({});
NativeDatePickerDisabled.args = {
dense: true,
type: 'date',
icon: 'calendar_today',
label: 'Datepicker',
disabled: true,
value: '2017-05-24'
};

0 comments on commit 3f3ddf4

Please sign in to comment.