@os-design/core 1.0.199 → 1.0.200
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +21 -13
- package/src/@types/emotion.d.ts +7 -0
- package/src/Alert/index.tsx +112 -0
- package/src/Avatar/index.tsx +173 -0
- package/src/Avatar/utils/nameToInitials.ts +12 -0
- package/src/Avatar/utils/strToHue.ts +13 -0
- package/src/AvatarSkeleton/index.tsx +29 -0
- package/src/Breadcrumb/index.tsx +93 -0
- package/src/BreadcrumbItem/index.tsx +83 -0
- package/src/Button/ButtonContent.tsx +91 -0
- package/src/Button/index.tsx +225 -0
- package/src/Button/utils/useButtonColors.ts +84 -0
- package/src/Checkbox/index.tsx +225 -0
- package/src/CheckboxSkeleton/index.tsx +50 -0
- package/src/DatePicker/DatePickerCalendar.tsx +220 -0
- package/src/DatePicker/index.tsx +568 -0
- package/src/Drawer/index.tsx +212 -0
- package/src/Form/FormConfigContext.ts +16 -0
- package/src/Form/index.tsx +49 -0
- package/src/FormDivider/index.tsx +74 -0
- package/src/FormItem/index.tsx +118 -0
- package/src/Gallery/Status.tsx +62 -0
- package/src/Gallery/index.tsx +290 -0
- package/src/GlobalStyles/index.tsx +17 -0
- package/src/GlobalStyles/resetStyles.ts +17 -0
- package/src/GlobalStyles/typographyStyles.ts +78 -0
- package/src/HeaderSkeleton/index.tsx +64 -0
- package/src/Image/index.tsx +104 -0
- package/src/ImageSkeleton/index.tsx +22 -0
- package/src/Input/index.tsx +330 -0
- package/src/Input/utils/getFocusableElements.ts +8 -0
- package/src/InputNumber/index.tsx +208 -0
- package/src/InputNumber/utils/defaultLocale.ts +9 -0
- package/src/InputPassword/index.tsx +201 -0
- package/src/InputPassword/utils/defaultLocale.ts +11 -0
- package/src/InputSearch/index.tsx +111 -0
- package/src/InputSearch/utils/defaultLocale.ts +9 -0
- package/src/InputSkeleton/index.tsx +28 -0
- package/src/Layout/LayoutContext.ts +21 -0
- package/src/Layout/index.tsx +44 -0
- package/src/Link/index.tsx +129 -0
- package/src/LinkButton/index.tsx +100 -0
- package/src/List/WindowScroller.tsx +53 -0
- package/src/List/index.tsx +255 -0
- package/src/List/utils/bodyPointerEvents.ts +24 -0
- package/src/List/utils/frameTimeout.ts +36 -0
- package/src/List/utils/useRWLoadNext.ts +38 -0
- package/src/ListItem/index.tsx +92 -0
- package/src/ListItemActions/index.tsx +207 -0
- package/src/ListItemLink/index.tsx +63 -0
- package/src/ListSkeleton/index.tsx +115 -0
- package/src/LogoLink/index.tsx +93 -0
- package/src/LogoLink/logo.example.svg +18 -0
- package/src/Menu/index.tsx +128 -0
- package/src/Menu/utils/useFocusWithArrows.ts +50 -0
- package/src/MenuDivider/index.tsx +22 -0
- package/src/MenuGroup/index.tsx +190 -0
- package/src/MenuItem/index.tsx +108 -0
- package/src/Modal/index.tsx +411 -0
- package/src/Modal/utils/defaultLocale.ts +9 -0
- package/src/Navigation/index.tsx +214 -0
- package/src/Navigation/utils/useScrollFlags.ts +39 -0
- package/src/NavigationItem/index.tsx +136 -0
- package/src/PageContent/index.tsx +99 -0
- package/src/PageHeader/index.tsx +246 -0
- package/src/PageHeader/utils/defaultLocale.ts +9 -0
- package/src/PageHeaderInputSearch/index.tsx +145 -0
- package/src/PageHeaderInputSearch/utils/defaultLocale.ts +16 -0
- package/src/PageHeaderSkeleton/index.tsx +33 -0
- package/src/ParagraphSkeleton/index.tsx +65 -0
- package/src/Popover/index.tsx +243 -0
- package/src/Popover/utils/usePopoverPosition.ts +216 -0
- package/src/Progress/index.tsx +100 -0
- package/src/RadioGroup/index.tsx +165 -0
- package/src/RadioGroupSkeleton/index.tsx +36 -0
- package/src/Result/index.tsx +109 -0
- package/src/ScrollButton/index.tsx +159 -0
- package/src/ScrollButton/utils/useContainerPosition.ts +41 -0
- package/src/ScrollButton/utils/useVisibility.ts +56 -0
- package/src/Select/index.tsx +970 -0
- package/src/Select/utils/defaultLocale.ts +11 -0
- package/src/Skeleton/index.tsx +52 -0
- package/src/Switch/index.tsx +217 -0
- package/src/SwitchSkeleton/index.tsx +30 -0
- package/src/Tag/index.tsx +75 -0
- package/src/TagLink/index.tsx +53 -0
- package/src/TagList/index.tsx +95 -0
- package/src/TagListSkeleton/index.tsx +38 -0
- package/src/TagSkeleton/index.tsx +40 -0
- package/src/TextArea/index.tsx +231 -0
- package/src/TextAreaSkeleton/index.tsx +20 -0
- package/src/ThemeSwitcher/index.tsx +39 -0
- package/src/TimePicker/index.tsx +142 -0
- package/src/Video/index.tsx +41 -0
- package/src/index.ts +125 -0
- package/src/message/AlertIcon.tsx +50 -0
- package/src/message/Message.tsx +108 -0
- package/src/message/index.tsx +64 -0
- package/src/message/styles.ts +25 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import styled from '@emotion/styled';
|
|
2
|
+
import {
|
|
3
|
+
DatePickerLocale,
|
|
4
|
+
getAccessibilityDateLabel,
|
|
5
|
+
useDatePickerCalendar,
|
|
6
|
+
} from '@os-design/date-picker-utils';
|
|
7
|
+
import { Left, Right } from '@os-design/icons';
|
|
8
|
+
import {
|
|
9
|
+
ellipsisStyles,
|
|
10
|
+
resetFocusStyles,
|
|
11
|
+
transitionStyles,
|
|
12
|
+
} from '@os-design/styles';
|
|
13
|
+
import { Color, clr } from '@os-design/theming';
|
|
14
|
+
|
|
15
|
+
import React, { HTMLAttributes, useCallback, useEffect, useRef } from 'react';
|
|
16
|
+
import Button from '../Button';
|
|
17
|
+
|
|
18
|
+
interface DatePickerCalendarProps {
|
|
19
|
+
firstDayOfWeek: 'sunday' | 'monday';
|
|
20
|
+
locale: DatePickerLocale;
|
|
21
|
+
value?: Date | [Date, Date] | null;
|
|
22
|
+
onSelect?: (value: Date) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const MonthContainer = styled.div`
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
margin-bottom: 0.5em;
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
const Month = styled.div`
|
|
32
|
+
flex-grow: 1;
|
|
33
|
+
font-weight: 500;
|
|
34
|
+
text-align: center;
|
|
35
|
+
padding: 0 0.4em;
|
|
36
|
+
${ellipsisStyles};
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
const Calendar = styled.div`
|
|
40
|
+
display: grid;
|
|
41
|
+
grid-template-columns: repeat(7, ${(p) => p.theme.datePickerCellSize}em);
|
|
42
|
+
grid-auto-rows: ${(p) => p.theme.datePickerCellSize}em;
|
|
43
|
+
justify-content: space-between;
|
|
44
|
+
overflow-x: auto;
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
const DayOfWeek = styled.div`
|
|
48
|
+
justify-self: center;
|
|
49
|
+
align-self: center;
|
|
50
|
+
color: ${(p) => clr(p.theme.datePickerDayOfWeekColorText)};
|
|
51
|
+
font-size: ${(p) => p.theme.sizes.small}em;
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
const Day = styled.div`
|
|
55
|
+
${resetFocusStyles};
|
|
56
|
+
justify-self: center;
|
|
57
|
+
align-self: center;
|
|
58
|
+
|
|
59
|
+
width: ${(p) => p.theme.datePickerDaySize}em;
|
|
60
|
+
height: ${(p) => p.theme.datePickerDaySize}em;
|
|
61
|
+
|
|
62
|
+
display: flex;
|
|
63
|
+
justify-content: center;
|
|
64
|
+
align-items: center;
|
|
65
|
+
|
|
66
|
+
border-radius: ${(p) => p.theme.borderRadius}em;
|
|
67
|
+
cursor: pointer;
|
|
68
|
+
|
|
69
|
+
@media (hover: hover) {
|
|
70
|
+
&:hover,
|
|
71
|
+
&:focus {
|
|
72
|
+
background-color: ${(p) => clr(p.theme.datePickerDayColorBgHover)};
|
|
73
|
+
color: ${(p) => clr(p.theme.datePickerDayColorTextHover)};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
${transitionStyles('background-color', 'color')};
|
|
78
|
+
`;
|
|
79
|
+
|
|
80
|
+
const DayAnotherMonth = styled(Day)`
|
|
81
|
+
color: ${(p) => clr(p.theme.datePickerDayAnotherMonthColorText)};
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
const Today = styled(Day)`
|
|
85
|
+
background-color: ${(p) => clr(p.theme.datePickerTodayColorBg)};
|
|
86
|
+
color: ${(p) => clr(p.theme.datePickerTodayColorText)};
|
|
87
|
+
border: 1px solid ${(p) => clr(p.theme.datePickerTodayColorBorder)};
|
|
88
|
+
box-sizing: border-box;
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
const SelectedDay = styled(Day)`
|
|
92
|
+
background-color: ${(p) => clr(p.theme.datePickerSelectedDayColorBg)};
|
|
93
|
+
color: ${(p) => clr(p.theme.datePickerSelectedDayColorText)};
|
|
94
|
+
`;
|
|
95
|
+
|
|
96
|
+
const DayInRange = styled(Day)`
|
|
97
|
+
background-color: ${(p) =>
|
|
98
|
+
clr([
|
|
99
|
+
...p.theme.colorText.slice(0, 3),
|
|
100
|
+
(p.theme.colorText[3] || 1) * 0.05,
|
|
101
|
+
] as Color)};
|
|
102
|
+
`;
|
|
103
|
+
|
|
104
|
+
const DatePickerCalendar: React.FC<DatePickerCalendarProps> = ({
|
|
105
|
+
firstDayOfWeek,
|
|
106
|
+
locale,
|
|
107
|
+
value,
|
|
108
|
+
onSelect = () => {},
|
|
109
|
+
}) => {
|
|
110
|
+
const valueRef = useRef(value);
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
valueRef.current = value;
|
|
113
|
+
}, [value]);
|
|
114
|
+
|
|
115
|
+
const onSelectRef = useRef(onSelect);
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
onSelectRef.current = onSelect;
|
|
118
|
+
}, [onSelect]);
|
|
119
|
+
|
|
120
|
+
const { selectedMonth, updateMonth, days } = useDatePickerCalendar({
|
|
121
|
+
value,
|
|
122
|
+
firstDayOfWeek,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const getDayProps = useCallback<
|
|
126
|
+
(date: Date) => HTMLAttributes<HTMLDivElement>
|
|
127
|
+
>(
|
|
128
|
+
(date: Date) => ({
|
|
129
|
+
tabIndex: 0,
|
|
130
|
+
role: 'button',
|
|
131
|
+
'aria-label': getAccessibilityDateLabel(date, locale),
|
|
132
|
+
onClick: () => {
|
|
133
|
+
onSelectRef.current(date);
|
|
134
|
+
},
|
|
135
|
+
onKeyDown: (e) => {
|
|
136
|
+
if (['Enter', ' '].includes(e.key)) {
|
|
137
|
+
onSelectRef.current(date);
|
|
138
|
+
e.preventDefault();
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
142
|
+
}),
|
|
143
|
+
[locale]
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<>
|
|
148
|
+
<MonthContainer>
|
|
149
|
+
<Button
|
|
150
|
+
type='ghost'
|
|
151
|
+
wide='never'
|
|
152
|
+
size='small'
|
|
153
|
+
onClick={() => updateMonth(-1)}
|
|
154
|
+
aria-label={locale.prevMonthLabel}
|
|
155
|
+
>
|
|
156
|
+
<Left />
|
|
157
|
+
</Button>
|
|
158
|
+
<Month>
|
|
159
|
+
{locale.months[selectedMonth.month]} {selectedMonth.year}
|
|
160
|
+
</Month>
|
|
161
|
+
<Button
|
|
162
|
+
type='ghost'
|
|
163
|
+
wide='never'
|
|
164
|
+
size='small'
|
|
165
|
+
onClick={() => updateMonth(1)}
|
|
166
|
+
aria-label={locale.nextMonthLabel}
|
|
167
|
+
>
|
|
168
|
+
<Right />
|
|
169
|
+
</Button>
|
|
170
|
+
</MonthContainer>
|
|
171
|
+
|
|
172
|
+
<Calendar>
|
|
173
|
+
{(firstDayOfWeek === 'sunday'
|
|
174
|
+
? locale.shortDaysOfWeek
|
|
175
|
+
: [...locale.shortDaysOfWeek.slice(1), locale.shortDaysOfWeek[0]]
|
|
176
|
+
).map((item) => (
|
|
177
|
+
<DayOfWeek key={item}>{item}</DayOfWeek>
|
|
178
|
+
))}
|
|
179
|
+
|
|
180
|
+
{days.map(({ type, date }) => {
|
|
181
|
+
if (type === 'dayAnotherMonth') {
|
|
182
|
+
return (
|
|
183
|
+
<DayAnotherMonth key={date.toISOString()} {...getDayProps(date)}>
|
|
184
|
+
{date.getDate()}
|
|
185
|
+
</DayAnotherMonth>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
if (type === 'selectedDay') {
|
|
189
|
+
return (
|
|
190
|
+
<SelectedDay key={date.toISOString()} {...getDayProps(date)}>
|
|
191
|
+
{date.getDate()}
|
|
192
|
+
</SelectedDay>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
if (type === 'dayInRange') {
|
|
196
|
+
return (
|
|
197
|
+
<DayInRange key={date.toISOString()} {...getDayProps(date)}>
|
|
198
|
+
{date.getDate()}
|
|
199
|
+
</DayInRange>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
if (type === 'today') {
|
|
203
|
+
return (
|
|
204
|
+
<Today key={date.toISOString()} {...getDayProps(date)}>
|
|
205
|
+
{date.getDate()}
|
|
206
|
+
</Today>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
return (
|
|
210
|
+
<Day key={date.toISOString()} {...getDayProps(date)}>
|
|
211
|
+
{date.getDate()}
|
|
212
|
+
</Day>
|
|
213
|
+
);
|
|
214
|
+
})}
|
|
215
|
+
</Calendar>
|
|
216
|
+
</>
|
|
217
|
+
);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export default DatePickerCalendar;
|