Skip to content

Commit 6768977

Browse files
authored
Add date field component (#27)
* Add date field component * Date field component * Fix tests * Add date field to react
1 parent 20c6d8a commit 6768977

35 files changed

+1608
-30
lines changed

packages/components/.eslintrc.js

-11
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@ module.exports = {
1212
},
1313
plugins: ['@typescript-eslint'],
1414
rules: {
15-
'@typescript-eslint/naming-convention': [
16-
'error',
17-
{
18-
selector: 'interface',
19-
format: ['PascalCase'],
20-
custom: {
21-
regex: '^I[A-Z]',
22-
match: true
23-
}
24-
}
25-
],
2615
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
2716
'@typescript-eslint/no-explicit-any': 'off',
2817
'@typescript-eslint/no-namespace': 'off',

packages/components/jest.config.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
const config = {
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
// preset: 'ts-jest/presets/default-esm',
5+
testEnvironment: 'node',
26
testMatch: ['**/?(*.)+(spec).ts']
7+
// globals: {
8+
// 'ts-jest': {
9+
// useESM: true
10+
// }
11+
// },
12+
// moduleNameMapper: {
13+
// '^(\\.{1,2}/.*)\\.js$': '$1'
14+
// }
315
};
4-
5-
module.exports = config;

packages/components/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,8 @@
6464
"@storybook/html": "^6.4.3",
6565
"@storybook/manager-webpack5": "^6.4.3",
6666
"@storybook/theming": "^6.4.3",
67-
"@types/jest": "^26.0.20",
67+
"@types/jest": "^27.0.0",
6868
"@typescript-eslint/eslint-plugin": "^4.8.1",
69-
"babel-jest": "^27.2.4",
70-
"babel-loader": "^8.2.2",
71-
"babel-plugin-transform-class-properties": "^6.24.1",
7269
"eslint": "^7.14.0",
7370
"eslint-config-prettier": "^6.15.0",
7471
"eslint-plugin-import": "^2.25.2",
@@ -81,6 +78,7 @@
8178
"rollup-plugin-filesize": "^9.1.1",
8279
"rollup-plugin-terser": "^7.0.2",
8380
"rollup-plugin-transform-tagged-template": "0.0.3",
81+
"ts-jest": "^27.0.0",
8482
"ts-loader": "^7.0.2",
8583
"tslib": "^2.1.0",
8684
"typescript": "~4.3.5",

packages/components/src/converters.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { ValueConverter } from '@microsoft/fast-element';
2+
3+
/**
4+
* A {@link ValueConverter} that converts to and from `Date` values.
5+
* @remarks
6+
* This converter allows for nullable Date, returning `null` if the
7+
* input was `null`, `undefined`, or a non-parsable date.
8+
* @public
9+
*/
10+
export const nullableDateConverter: ValueConverter = {
11+
toView(value?: Date | null): string | null {
12+
if (value === null || value === undefined) {
13+
return null;
14+
}
15+
const date = new Date(value);
16+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#return_value
17+
return date.toString() === 'Invalid Date'
18+
? null
19+
: `${date.getFullYear().toString().padStart(4, '0')}-${(
20+
date.getMonth() + 1
21+
)
22+
.toString()
23+
.padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
24+
},
25+
26+
fromView(value?: string | null): Date | null {
27+
if (value === null || value === undefined) {
28+
return null;
29+
}
30+
31+
const date = new Date(value);
32+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#return_value
33+
return date.toString() === 'Invalid Date' ? null : date;
34+
}
35+
};

packages/components/src/custom-elements.ts

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { jpCard } from './card/index';
1414
import { jpCheckbox } from './checkbox/index';
1515
import { jpCombobox } from './combobox/index';
1616
import { jpDataGrid, jpDataGridCell, jpDataGridRow } from './data-grid/index';
17+
import { jpDateField } from './date-field/index';
1718
import { jpDivider } from './divider/index';
1819
import { jpMenu } from './menu/index';
1920
import { jpMenuItem } from './menu-item/index';
@@ -53,6 +54,7 @@ import type { Card } from './card/index';
5354
import type { Checkbox } from './checkbox/index';
5455
import type { Combobox } from './combobox/index';
5556
import type { DataGrid, DataGridCell, DataGridRow } from './data-grid/index';
57+
import type { DateField } from './date-field/index';
5658
import type { Divider } from './divider/index';
5759
import type { Menu } from './menu/index';
5860
import type { MenuItem } from './menu-item/index';
@@ -93,6 +95,7 @@ export {
9395
jpDataGrid,
9496
jpDataGridCell,
9597
jpDataGridRow,
98+
jpDateField,
9699
jpDivider,
97100
jpMenu,
98101
jpMenuItem,
@@ -140,6 +143,7 @@ export const allComponents = {
140143
jpDataGrid,
141144
jpDataGridCell,
142145
jpDataGridRow,
146+
jpDateField,
143147
jpDivider,
144148
jpMenu,
145149
jpMenuItem,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { FormAssociated, FoundationElement } from '@microsoft/fast-foundation';
2+
3+
class _DateField extends FoundationElement {}
4+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
5+
interface _DateField extends FormAssociated {}
6+
7+
/**
8+
* A form-associated base class for the {@link @jupyter-notebook/web-components#(DateField:class)} component.
9+
*
10+
* @internal
11+
*/
12+
export class FormAssociatedDateField extends FormAssociated(_DateField) {
13+
proxy = document.createElement('input');
14+
}

0 commit comments

Comments
 (0)