Skip to content

Commit 10e2cf9

Browse files
committed
init date picker types
1 parent 66f7a30 commit 10e2cf9

File tree

6 files changed

+114
-9
lines changed

6 files changed

+114
-9
lines changed

packages/date-picker/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@leafygreen-ui/date-picker",
2+
"name": "@leafygreen-ui/date-picker",
33
"version": "0.1.0",
44
"description": "LeafyGreen UI Kit Date Picker",
55
"main": "./dist/index.js",
@@ -15,8 +15,12 @@
1515
"access": "public"
1616
},
1717
"dependencies": {
18-
"@leafygreen-ui/emotion": "^4.0.4",
19-
"@leafygreen-ui/lib": "^10.4.0"
18+
"@leafygreen-ui/emotion": "^4.0.7",
19+
"@leafygreen-ui/lib": "^10.4.3",
20+
"@leafygreen-ui/tokens": "^2.1.4"
21+
},
22+
"peerDependencies": {
23+
"@leafygreen-ui/leafygreen-provider": "^3.1.6"
2024
},
2125
"homepage": "https://github.com/mongodb/leafygreen-ui/tree/main/packages/date-picker",
2226
"repository": {
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import React from 'react';
1+
import React, { forwardRef } from 'react';
22

3-
// TODO: forwardRef
4-
export function DatePicker({}) {
3+
import { DatePickerProps } from './DatePicker.types';
4+
5+
// eslint-disable-next-line no-empty-pattern
6+
export const DatePicker = forwardRef(({}: DatePickerProps) => {
57
return <div>your content here</div>;
6-
}
8+
});
79

810
DatePicker.displayName = 'DatePicker';
Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,25 @@
1-
export interface DatePickerProps {}
1+
import { BaseDatePickerProps } from 'src/types';
2+
3+
export interface DatePickerProps extends BaseDatePickerProps {
4+
/** The initial selected date. Ignored if `value` is provided */
5+
initialValue: string | Date;
6+
7+
/** The selected date */
8+
value: string | Date;
9+
10+
/**
11+
* A Callback fired when the user makes a value change.
12+
* Fired on click of a new date in the menu, or on keydown if the input contains a valid date
13+
*
14+
* Callback date argument will be a Date object in ISO-8601 format, and in UTC time.
15+
*/
16+
onChange: (value: Date) => void;
17+
18+
/**
19+
* A callback fired when validation should run, based on our [form validation guidelines](https://www.mongodb.design/foundation/forms/#form-validation-error-handling).
20+
* Use this callback to compute the correct `state` value.
21+
*
22+
* Callback date argument will be a Date object in ISO 8601 format, and in UTC time.
23+
*/
24+
handleValidation: (value: Date) => void;
25+
}

packages/date-picker/src/types.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { DarkModeProps } from '@leafygreen-ui/lib';
2+
import { BaseFontSize } from '@leafygreen-ui/tokens';
3+
4+
const Size = {
5+
xsmall: 'xsmall',
6+
small: 'small',
7+
default: 'default',
8+
large: 'large',
9+
};
10+
type Size = typeof Size[keyof typeof Size];
11+
12+
export interface BaseDatePickerProps extends DarkModeProps {
13+
/**
14+
* A label for the input
15+
*/
16+
label: string;
17+
18+
/**
19+
* Sets the _presentation format_ for the displayed date.
20+
* Fallback to the user’s browser preference (if supported), otherwise ISO-8601.
21+
*
22+
* Currently only the following values are officially supported.
23+
* Other valid [Locale](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
24+
* strings may work, however no assurances are made.
25+
*
26+
* @enum 'en-US' | 'en-UK' | 'iso8601'
27+
*
28+
* @default 'iso8601'
29+
*/
30+
dateFormat?: string;
31+
32+
/**
33+
* A valid IANA timezone string, or UTC offset.
34+
* Sets the _presentation time zone_ for the displayed date.
35+
* Fallback to the user’s browser preference (if available), otherwise UTC.
36+
*
37+
* @default 'utc'
38+
*/
39+
timeZone?: string;
40+
41+
/** The earliest date accepted */
42+
min?: string | Date;
43+
44+
/** The latest date accepted */
45+
max?: string | Date;
46+
47+
/**
48+
* The base font size of the input. Inherits from the nearest LeafyGreenProvider
49+
*/
50+
baseFontSize?: BaseFontSize;
51+
52+
/**
53+
* Whether the input is disabled. Note: will not set the `disabled` attribute on an input
54+
*/
55+
disabled?: boolean;
56+
57+
/** The size of the input */
58+
size?: Size;
59+
60+
/**
61+
* Whether to show an error message
62+
*/
63+
state?: 'unset' | 'error';
64+
65+
/**
66+
* A message to show in red underneath the input when in an error state
67+
*/
68+
errorMessage?: string;
69+
}

packages/date-picker/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@
1818
{
1919
"path": "../emotion"
2020
},
21+
{
22+
"path": "../leafygreen-provider"
23+
},
2124
{
2225
"path": "../lib"
26+
},
27+
{
28+
"path": "../tokens"
2329
}
2430
]
2531
}

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6856,7 +6856,7 @@ camelcase@^7.0.0:
68566856
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-7.0.1.tgz#f02e50af9fd7782bc8b88a3558c32fd3a388f048"
68576857
integrity sha512-xlx1yCK2Oc1APsPXDL2LdlNP6+uu8OCDdhOBSVT279M/S+y75O30C2VuD8T2ogdePBBl7PfPF4504tnLgX3zfw==
68586858

6859-
caniuse-lite@^1.0.30001135, caniuse-lite@^1.0.30001406, caniuse-lite@^1.0.30001449, caniuse-lite@^1.0.30001503:
6859+
caniuse-lite@^1.0.30001406, caniuse-lite@^1.0.30001449, caniuse-lite@^1.0.30001503:
68606860
version "1.0.30001519"
68616861
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001519.tgz#3e7b8b8a7077e78b0eb054d69e6edf5c7df35601"
68626862
integrity sha512-0QHgqR+Jv4bxHMp8kZ1Kn8CH55OikjKJ6JmKkZYP1F3D7w+lnFXF70nG5eNfsZS89jadi5Ywy5UCSKLAglIRkg==

0 commit comments

Comments
 (0)