-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
) * feat: add RangeCalendarExample component * feat: add RangeCalendar sandbox * feat: add RangeCalendarWithDefaultValueExample * feat: update date-components * fix: text value * fix: positioning items in example block row * feat: set positioning to center
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,49 @@ | ||
import dynamic from 'next/dynamic'; | ||
import {Repos} from 'src/types/common'; | ||
|
||
import {Component} from '../../types'; | ||
import {getGithubUrl, getReadmeUrl, mappingOptions} from '../../utils'; | ||
|
||
const getterOptions = {repoName: Repos.DateComponents, componentName: 'RangeCalendar'}; | ||
|
||
export const rangeCalendarConfig: Component = { | ||
id: 'range-calendar', | ||
title: 'Range Calendar', | ||
isComingSoon: true, | ||
githubUrl: getGithubUrl(getterOptions), | ||
content: { | ||
readmeUrl: getReadmeUrl(getterOptions), | ||
}, | ||
sandbox: { | ||
component: dynamic(() => | ||
import('../examples/components/index').then((mod) => mod.RangeCalendarExample), | ||
), | ||
props: { | ||
size: { | ||
type: 'radioButton', | ||
values: mappingOptions(['m', 'l', 'xl']), | ||
defaultValue: 'm', | ||
}, | ||
mode: { | ||
type: 'select', | ||
values: mappingOptions(['days', 'months', 'quarters', 'years']), | ||
}, | ||
disabled: { | ||
type: 'switch', | ||
defaultValue: false, | ||
}, | ||
readOnly: { | ||
type: 'switch', | ||
defaultValue: false, | ||
}, | ||
minValue: { | ||
type: 'input', | ||
}, | ||
maxValue: { | ||
type: 'input', | ||
}, | ||
focusedValue: { | ||
type: 'input', | ||
}, | ||
}, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {RangeCalendar, RangeCalendarProps} from '@gravity-ui/date-components'; | ||
import {RangeValue} from '@gravity-ui/date-components/dist/esm/components/types'; | ||
import {DateTime, DateTimeInput, dateTime, dateTimeParse} from '@gravity-ui/date-utils'; | ||
import React from 'react'; | ||
|
||
type RangeCalendarExampleProps = { | ||
defaultValue?: RangeValue<DateTimeInput>; | ||
maxValue?: DateTimeInput; | ||
minValue?: DateTimeInput; | ||
defaultFocusedValue?: DateTimeInput; | ||
focusedValue?: DateTimeInput; | ||
} & Omit< | ||
RangeCalendarProps, | ||
'defaultValue' | 'maxValue' | 'minValue' | 'defaultFocusedValue' | 'focusedValue' | ||
>; | ||
|
||
const SelectedRangeText = ({value}: {value?: RangeValue<DateTime>}) => ( | ||
<div style={{textAlign: 'center'}}> | ||
<div>Selected range:</div> | ||
<div>{value ? `${value.start?.format('L')} - ${value.end?.format('L')}` : '\u00A0'}</div> | ||
</div> | ||
); | ||
|
||
export const RangeCalendarExample = ({ | ||
focusedValue, | ||
defaultFocusedValue, | ||
defaultValue, | ||
maxValue, | ||
minValue, | ||
...otherProps | ||
}: RangeCalendarExampleProps) => { | ||
const modes: RangeCalendarExampleProps['modes'] = { | ||
days: true, | ||
months: true, | ||
quarters: true, | ||
years: true, | ||
}; | ||
|
||
const parsedDefaultValue: RangeCalendarProps['defaultValue'] = defaultValue | ||
? {start: dateTimeParse(defaultValue.start)!, end: dateTimeParse(defaultValue.end)!} | ||
Check warning on line 40 in src/content/components/date-components/examples/components/RangeCalendarExample.tsx GitHub Actions / Verify Files
Check warning on line 40 in src/content/components/date-components/examples/components/RangeCalendarExample.tsx GitHub Actions / Verify Files
Check warning on line 40 in src/content/components/date-components/examples/components/RangeCalendarExample.tsx GitHub Actions / deploy (18.x)
Check warning on line 40 in src/content/components/date-components/examples/components/RangeCalendarExample.tsx GitHub Actions / deploy (18.x)
Check warning on line 40 in src/content/components/date-components/examples/components/RangeCalendarExample.tsx GitHub Actions / deploy (18.x)
Check warning on line 40 in src/content/components/date-components/examples/components/RangeCalendarExample.tsx GitHub Actions / deploy (18.x)
Check warning on line 40 in src/content/components/date-components/examples/components/RangeCalendarExample.tsx GitHub Actions / deploy (18.x)
|
||
: undefined; | ||
|
||
const [value, setValue] = React.useState(parsedDefaultValue); | ||
return ( | ||
<div> | ||
<RangeCalendar | ||
{...otherProps} | ||
defaultFocusedValue={dateTimeParse(defaultFocusedValue)} | ||
defaultValue={parsedDefaultValue} | ||
minValue={dateTimeParse(minValue)} | ||
maxValue={dateTimeParse(maxValue)} | ||
focusedValue={dateTimeParse(focusedValue)} | ||
onUpdate={setValue} | ||
modes={modes} | ||
/> | ||
<SelectedRangeText value={value} /> | ||
</div> | ||
); | ||
}; | ||
|
||
type RangeCalendarWithDefaultValueExampleProps = Omit<RangeCalendarExampleProps, 'defaultValue'>; | ||
|
||
export const RangeCalendarWithDefaultValueExample = ( | ||
props: RangeCalendarWithDefaultValueExampleProps, | ||
) => { | ||
const today = dateTime(); | ||
const defaultValue: RangeValue<string> = { | ||
start: today.subtract({days: 2}).toString(), | ||
end: today.add({days: 2}).toString(), | ||
}; | ||
return <RangeCalendarExample {...props} defaultValue={defaultValue} />; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './CalendarExample'; | ||
export * from './RangeCalendarExample'; | ||
export * from './DateFieldExample'; |