forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(react-datepicker): Create Calendar components and DatePicker co…
…mponent (microsoft#26325) * add Calendar components and DatePicker component * fix lint error * missed one
- Loading branch information
1 parent
968a908
commit e5f9e8c
Showing
101 changed files
with
1,468 additions
and
3 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
packages/react-components/react-datepicker/.storybook/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const rootMain = require('../../../../.storybook/main'); | ||
|
||
module.exports = /** @type {Omit<import('../../../../.storybook/main'), 'typescript'|'babel'>} */ ({ | ||
...rootMain, | ||
stories: [...rootMain.stories, '../stories/**/*.stories.mdx', '../stories/**/index.stories.@(ts|tsx)'], | ||
addons: [...rootMain.addons], | ||
webpackFinal: (config, options) => { | ||
const localConfig = { ...rootMain.webpackFinal(config, options) }; | ||
|
||
// add your own webpack tweaks if needed | ||
|
||
return localConfig; | ||
}, | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/react-components/react-datepicker/.storybook/preview.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as rootPreview from '../../../../.storybook/preview'; | ||
|
||
/** @type {typeof rootPreview.decorators} */ | ||
export const decorators = [...rootPreview.decorators]; | ||
|
||
/** @type {typeof rootPreview.parameters} */ | ||
export const parameters = { ...rootPreview.parameters }; |
10 changes: 10 additions & 0 deletions
10
packages/react-components/react-datepicker/.storybook/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "", | ||
"allowJs": true, | ||
"checkJs": true, | ||
"types": ["static-assets", "environment", "storybook__addons"] | ||
}, | ||
"include": ["../stories/**/*.stories.ts", "../stories/**/*.stories.tsx", "*.js"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/Calendar/index'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/CalendarDay/index'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/CalendarGrid/index'; |
1 change: 1 addition & 0 deletions
1
packages/react-components/react-datepicker/src/CalendarMonth.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/CalendarMonth/index'; |
1 change: 1 addition & 0 deletions
1
packages/react-components/react-datepicker/src/CalendarPicker.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/CalendarPicker/index'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/CalendarYear/index'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/DatePicker/index'; |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-datepicker/src/components/Calendar/Calendar.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { Calendar } from './Calendar'; | ||
import { isConformant } from '../../testing/isConformant'; | ||
|
||
describe('Calendar', () => { | ||
isConformant({ | ||
Component: Calendar, | ||
displayName: 'Calendar', | ||
}); | ||
|
||
// TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
||
it('renders a default state', () => { | ||
const result = render(<Calendar>Default Calendar</Calendar>); | ||
expect(result.container).toMatchSnapshot(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-datepicker/src/components/Calendar/Calendar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as React from 'react'; | ||
import { useCalendar_unstable } from './useCalendar'; | ||
import { renderCalendar_unstable } from './renderCalendar'; | ||
import { useCalendarStyles_unstable } from './useCalendarStyles'; | ||
import type { CalendarProps } from './Calendar.types'; | ||
import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
|
||
/** | ||
* Calendar component - TODO: add more docs | ||
*/ | ||
export const Calendar: ForwardRefComponent<CalendarProps> = React.forwardRef((props, ref) => { | ||
const state = useCalendar_unstable(props, ref); | ||
|
||
useCalendarStyles_unstable(state); | ||
return renderCalendar_unstable(state); | ||
}); | ||
|
||
Calendar.displayName = 'Calendar'; |
16 changes: 16 additions & 0 deletions
16
packages/react-components/react-datepicker/src/components/Calendar/Calendar.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
|
||
export type CalendarSlots = { | ||
root: Slot<'div'>; | ||
}; | ||
|
||
/** | ||
* Calendar Props | ||
*/ | ||
export type CalendarProps = ComponentProps<CalendarSlots> & {}; | ||
|
||
/** | ||
* State used in rendering Calendar | ||
*/ | ||
export type CalendarState = ComponentState<CalendarSlots>; | ||
// & Required<Pick<CalendarProps, 'propName'>> |
11 changes: 11 additions & 0 deletions
11
...-components/react-datepicker/src/components/Calendar/__snapshots__/Calendar.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Calendar renders a default state 1`] = ` | ||
<div> | ||
<div | ||
class="fui-Calendar" | ||
> | ||
Default Calendar | ||
</div> | ||
</div> | ||
`; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-datepicker/src/components/Calendar/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './Calendar'; | ||
export * from './Calendar.types'; | ||
export * from './renderCalendar'; | ||
export * from './useCalendar'; | ||
export * from './useCalendarStyles'; |
13 changes: 13 additions & 0 deletions
13
packages/react-components/react-datepicker/src/components/Calendar/renderCalendar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as React from 'react'; | ||
import { getSlots } from '@fluentui/react-utilities'; | ||
import type { CalendarState, CalendarSlots } from './Calendar.types'; | ||
|
||
/** | ||
* Render the final JSX of Calendar | ||
*/ | ||
export const renderCalendar_unstable = (state: CalendarState) => { | ||
const { slots, slotProps } = getSlots<CalendarSlots>(state); | ||
|
||
// TODO Add additional slots in the appropriate place | ||
return <slots.root {...slotProps.root} />; | ||
}; |
28 changes: 28 additions & 0 deletions
28
packages/react-components/react-datepicker/src/components/Calendar/useCalendar.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as React from 'react'; | ||
import { getNativeElementProps } from '@fluentui/react-utilities'; | ||
import type { CalendarProps, CalendarState } from './Calendar.types'; | ||
|
||
/** | ||
* Create the state required to render Calendar. | ||
* | ||
* The returned state can be modified with hooks such as useCalendarStyles_unstable, | ||
* before being passed to renderCalendar_unstable. | ||
* | ||
* @param props - props from this instance of Calendar | ||
* @param ref - reference to root HTMLElement of Calendar | ||
*/ | ||
export const useCalendar_unstable = (props: CalendarProps, ref: React.Ref<HTMLElement>): CalendarState => { | ||
return { | ||
// TODO add appropriate props/defaults | ||
components: { | ||
// TODO add each slot's element type or component | ||
root: 'div', | ||
}, | ||
// TODO add appropriate slots, for example: | ||
// mySlot: resolveShorthand(props.mySlot), | ||
root: getNativeElementProps('div', { | ||
ref, | ||
...props, | ||
}), | ||
}; | ||
}; |
Oops, something went wrong.