fix(core): date-picker styles (#8997)

fix AF-1871
This commit is contained in:
pengx17
2024-12-04 06:56:26 +00:00
parent 1fa1a95c10
commit 4706f1e2a3
7 changed files with 48 additions and 27 deletions

View File

@@ -5,6 +5,8 @@ import { createVar, style } from '@vanilla-extract/css';
export const vars = { export const vars = {
gapX: createVar('gapX'), gapX: createVar('gapX'),
gapY: createVar('gapY'), gapY: createVar('gapY'),
cellFontSize: createVar('cellFontSize'),
cellSize: createVar('cellSize'),
}; };
// basic // basic
@@ -82,9 +84,9 @@ export const basicCell = style({
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
minWidth: '28px', width: vars.cellSize,
maxWidth: '56px', height: vars.cellSize,
flex: '1', flexBasis: vars.cellSize,
userSelect: 'none', userSelect: 'none',
}); });
@@ -138,11 +140,16 @@ export const calendarHeaderTriggerButton = style([
{ {
display: 'inline-flex', display: 'inline-flex',
lineHeight: '22px', lineHeight: '22px',
fontSize: 'var(--affine-font-sm)', fontSize: vars.cellFontSize,
fontWeight: 600, fontWeight: 600,
padding: '2px 6px', padding: '0 6px',
borderRadius: 4, borderRadius: 4,
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
selectors: {
'[data-mobile="true"] &': {
padding: '0px 4px',
},
},
}, },
]); ]);
export const headerNavButtons = style({ export const headerNavButtons = style({
@@ -156,7 +163,7 @@ export const headerNavGapFallback = style({
export const headerNavToday = style([ export const headerNavToday = style([
interactive, interactive,
{ {
fontSize: 'var(--affine-font-sm)', fontSize: vars.cellFontSize,
fontWeight: 400, fontWeight: 400,
lineHeight: '22px', lineHeight: '22px',
padding: '0 4px', padding: '0 4px',
@@ -181,18 +188,13 @@ export const monthViewRow = style({
export const monthViewHeaderCell = style([ export const monthViewHeaderCell = style([
basicCell, basicCell,
{ {
fontSize: 'var(--affine-font-xs)', fontSize: vars.cellFontSize,
fontWeight: 500, fontWeight: 500,
color: cssVar('textSecondaryColor'), color: cssVar('textSecondaryColor'),
height: 28, height: 28,
}, },
]); ]);
export const monthViewBodyCell = style([ export const monthViewBodyCell = style([basicCell]);
basicCell,
{
height: '28px',
},
]);
export const monthViewBodyCellInner = style([ export const monthViewBodyCellInner = style([
interactive, interactive,
@@ -200,7 +202,7 @@ export const monthViewBodyCellInner = style([
width: '100%', width: '100%',
height: '100%', height: '100%',
borderRadius: 8, borderRadius: 8,
fontSize: cssVar('fontSm'), fontSize: vars.cellFontSize,
color: cssVar('textPrimaryColor'), color: cssVar('textPrimaryColor'),
fontWeight: 400, fontWeight: 400,

View File

@@ -18,7 +18,7 @@ export type { DatePickerProps } from './types';
*/ */
export const DatePicker = (props: DatePickerProps) => { export const DatePicker = (props: DatePickerProps) => {
const finalProps = { ...defaultDatePickerProps, ...props }; const finalProps = { ...defaultDatePickerProps, ...props };
const { value, gapX, gapY, onChange } = finalProps; const { value, gapX, gapY, cellFontSize, cellSize, onChange } = finalProps;
const [mode, setMode] = useState<SelectMode>('day'); const [mode, setMode] = useState<SelectMode>('day');
const [cursor, setCursor] = useState(dayjs(value)); const [cursor, setCursor] = useState(dayjs(value));
@@ -26,6 +26,8 @@ export const DatePicker = (props: DatePickerProps) => {
const variables = assignInlineVars({ const variables = assignInlineVars({
[styles.vars.gapX]: `${gapX}px`, [styles.vars.gapX]: `${gapX}px`,
[styles.vars.gapY]: `${gapY}px`, [styles.vars.gapY]: `${gapY}px`,
[styles.vars.cellFontSize]: `${cellFontSize}px`,
[styles.vars.cellSize]: `${cellSize}px`,
}); });
const Component = const Component =
mode === 'day' ? DayPicker : mode === 'month' ? MonthPicker : YearPicker; mode === 'day' ? DayPicker : mode === 'month' ? MonthPicker : YearPicker;

View File

@@ -80,7 +80,12 @@ export const CalendarLayout = forwardRef<HTMLDivElement, CalendarLayoutProps>(
ref ref
) => { ) => {
return ( return (
<div className={styles.calendarWrapper} ref={ref} data-mode={mode}> <div
className={styles.calendarWrapper}
ref={ref}
data-mode={mode}
data-mobile={BUILD_CONFIG.isMobileEdition}
>
<HeaderLayout <HeaderLayout
mode={mode} mode={mode}
length={length} length={length}
@@ -124,6 +129,9 @@ interface NavButtonsProps extends PropsWithChildren {
onPrev?: () => void; onPrev?: () => void;
onNext?: () => void; onNext?: () => void;
} }
const iconButtonSize = BUILD_CONFIG.isMobileEdition ? 28 : 16;
export const NavButtons = memo(function NavButtons({ export const NavButtons = memo(function NavButtons({
children, children,
prevDisabled, prevDisabled,
@@ -135,7 +143,7 @@ export const NavButtons = memo(function NavButtons({
<div className={styles.headerNavButtons} key="nav-btn-group"> <div className={styles.headerNavButtons} key="nav-btn-group">
<IconButton <IconButton
key="nav-btn-prev" key="nav-btn-prev"
size="16" size={iconButtonSize}
disabled={prevDisabled} disabled={prevDisabled}
data-testid="date-picker-nav-prev" data-testid="date-picker-nav-prev"
onClick={onPrev} onClick={onPrev}
@@ -147,7 +155,7 @@ export const NavButtons = memo(function NavButtons({
<IconButton <IconButton
key="nav-btn-next" key="nav-btn-next"
size="16" size={iconButtonSize}
disabled={nextDisabled} disabled={nextDisabled}
data-testid="date-picker-nav-next" data-testid="date-picker-nav-next"
onClick={onNext} onClick={onNext}

View File

@@ -14,7 +14,7 @@ export interface DatePickerProps {
/** /**
* Customize the vertical gap between each row, in `px` * Customize the vertical gap between each row, in `px`
* @default 8 * @default 8 (mobile: 16)
*/ */
gapY?: number; gapY?: number;
@@ -25,6 +25,18 @@ export interface DatePickerProps {
*/ */
gapX?: number; gapX?: number;
/**
* Customize the size of the cell, in `px`
* @default 28 (mobile: 34)
*/
cellSize?: number;
/**
* Customize the font size of the cell, in `px`
* @default 14 (mobile: 17)
*/
cellFontSize?: number;
/** /**
* Customize weekdays, use `,` to separate each day * Customize weekdays, use `,` to separate each day
* @default {} `'Su,Mo,Tu,We,Th,Fr,Sa'` * @default {} `'Su,Mo,Tu,We,Th,Fr,Sa'`
@@ -73,7 +85,9 @@ export type SelectMode = 'day' | 'month' | 'year';
export const defaultDatePickerProps = { export const defaultDatePickerProps = {
format: 'YYYY-MM-DD', format: 'YYYY-MM-DD',
gapX: 8, gapX: 8,
gapY: 8, gapY: BUILD_CONFIG.isMobileEdition ? 16 : 8,
cellFontSize: BUILD_CONFIG.isMobileEdition ? 17 : 14,
cellSize: BUILD_CONFIG.isMobileEdition ? 34 : 28,
weekDays: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'].join(','), weekDays: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'].join(','),
monthNames: [ monthNames: [
'Jan', 'Jan',

View File

@@ -109,7 +109,7 @@ export const JournalValue = ({ onChange }: PropertyValueProps) => {
onClick: e => e.stopPropagation(), onClick: e => e.stopPropagation(),
sideOffset: 10, sideOffset: 10,
alignOffset: -30, alignOffset: -30,
style: { padding: 20 }, style: { padding: '15px 20px' },
}} }}
rootOptions={{ rootOptions={{
modal: true, modal: true,

View File

@@ -251,7 +251,3 @@ export const journalDateCellDot = style({
left: '50%', left: '50%',
transform: 'translateX(-50%)', transform: 'translateX(-50%)',
}); });
export const journalDateCellWrapper = style({
height: 34,
});

View File

@@ -154,8 +154,7 @@ export const EditorJournalPanel = () => {
customDayRenderer={customDayRenderer} customDayRenderer={customDayRenderer}
value={journalDate?.format('YYYY-MM-DD')} value={journalDate?.format('YYYY-MM-DD')}
onChange={onDateSelect} onChange={onDateSelect}
monthHeaderCellClassName={styles.journalDateCellWrapper} cellSize={34}
monthBodyCellClassName={styles.journalDateCellWrapper}
/> />
</div> </div>
{journalDate ? ( {journalDate ? (