Skip to content

Commit 8233b8f

Browse files
committed
init date picker types
1 parent d5a9f77 commit 8233b8f

File tree

6 files changed

+122
-8
lines changed

6 files changed

+122
-8
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,15 @@
22582258
resolved "https://registry.yarnpkg.com/@juggle/resize-observer/-/resize-observer-3.4.0.tgz#08d6c5e20cf7e4cc02fd181c4b0c225cd31dbb60"
22592259
integrity sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==
22602260

2261+
"@leafygreen-ui/lib@^10.4.3":
2262+
version "10.4.3"
2263+
resolved "https://registry.yarnpkg.com/@leafygreen-ui/lib/-/lib-10.4.3.tgz#f5ebdabc82922067adee8f37833237685bb1b1a8"
2264+
integrity sha512-p5BtXHeQsvLnnrN0eunPFZeaMtW9z7Mbvm2WOS9lvnAySj8xZp5Vn9Y3XjyYLbPhpGVBhhOAJFP3YMxbP9DKgg==
2265+
dependencies:
2266+
"@storybook/csf" "^0.1.0"
2267+
lodash "^4.17.21"
2268+
prop-types "^15.7.2"
2269+
22612270
"@manypkg/find-root@^1.1.0":
22622271
version "1.1.0"
22632272
resolved "https://registry.yarnpkg.com/@manypkg/find-root/-/find-root-1.1.0.tgz#a62d8ed1cd7e7d4c11d9d52a8397460b5d4ad29f"

0 commit comments

Comments
 (0)