@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,108 @@
|
|
|
1
|
+
import { keyframes } from '@emotion/react';
|
|
2
|
+
import styled from '@emotion/styled';
|
|
3
|
+
import { ellipsisStyles } from '@os-design/styles';
|
|
4
|
+
import { clr, Color, light } from '@os-design/theming';
|
|
5
|
+
import { omitEmotionProps } from '@os-design/utils';
|
|
6
|
+
import React, { forwardRef } from 'react';
|
|
7
|
+
import AlertIcon from './AlertIcon';
|
|
8
|
+
|
|
9
|
+
export interface MessageProps {
|
|
10
|
+
type: 'info' | 'success' | 'error';
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const fadeIn = keyframes`
|
|
15
|
+
from {
|
|
16
|
+
opacity: 0;
|
|
17
|
+
transform: translateY(-100%);
|
|
18
|
+
}
|
|
19
|
+
to {
|
|
20
|
+
opacity: 1;
|
|
21
|
+
transform: translateY(0);
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
const MESSAGE_HEIGHT_EM = 2.5;
|
|
26
|
+
const MESSAGE_MARGIN_TOP_EM = 0.7;
|
|
27
|
+
export const MESSAGE_DURATION_MS = 3000;
|
|
28
|
+
|
|
29
|
+
const fadeOut = keyframes`
|
|
30
|
+
from {
|
|
31
|
+
opacity: 1;
|
|
32
|
+
height: ${MESSAGE_HEIGHT_EM}em;
|
|
33
|
+
margin-top: ${MESSAGE_MARGIN_TOP_EM}em;
|
|
34
|
+
transform: translateY(0);
|
|
35
|
+
}
|
|
36
|
+
to {
|
|
37
|
+
opacity: 0;
|
|
38
|
+
height: 0;
|
|
39
|
+
margin-top: 0;
|
|
40
|
+
transform: translateY(-100%);
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
interface ContainerProps extends Pick<MessageProps, 'type'> {
|
|
45
|
+
textColor: Color;
|
|
46
|
+
backgroundColor: Color;
|
|
47
|
+
transitionDelay: number;
|
|
48
|
+
}
|
|
49
|
+
const Container = styled(
|
|
50
|
+
'div',
|
|
51
|
+
omitEmotionProps('type', 'textColor', 'backgroundColor', 'transitionDelay')
|
|
52
|
+
)<ContainerProps>`
|
|
53
|
+
display: flex;
|
|
54
|
+
flex-direction: row;
|
|
55
|
+
align-items: center;
|
|
56
|
+
|
|
57
|
+
height: ${MESSAGE_HEIGHT_EM}em;
|
|
58
|
+
margin-top: ${MESSAGE_MARGIN_TOP_EM}em;
|
|
59
|
+
|
|
60
|
+
box-sizing: border-box;
|
|
61
|
+
padding: 0 1em;
|
|
62
|
+
max-width: 90%;
|
|
63
|
+
|
|
64
|
+
border-radius: 0.25em;
|
|
65
|
+
box-shadow: 0 0.15em 0.45em hsla(0, 0%, 0%, 0.1);
|
|
66
|
+
background-color: ${(p) => clr(p.backgroundColor)};
|
|
67
|
+
color: ${(p) => clr(p.textColor)};
|
|
68
|
+
|
|
69
|
+
pointer-events: auto;
|
|
70
|
+
overflow: hidden;
|
|
71
|
+
|
|
72
|
+
animation: ${fadeIn} ${(p) => p.transitionDelay}ms,
|
|
73
|
+
${fadeOut} ${(p) => p.transitionDelay}ms
|
|
74
|
+
${(p) => MESSAGE_DURATION_MS - p.transitionDelay}ms;
|
|
75
|
+
animation-fill-mode: forwards;
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
const Text = styled.span`
|
|
79
|
+
${ellipsisStyles};
|
|
80
|
+
`;
|
|
81
|
+
|
|
82
|
+
const Message = forwardRef<HTMLDivElement, MessageProps>(
|
|
83
|
+
({ type, text }, ref) => {
|
|
84
|
+
const backgroundColor = {
|
|
85
|
+
info: light.messageInfoColorBg,
|
|
86
|
+
success: light.messageSuccessColorBg,
|
|
87
|
+
error: light.messageErrorColorBg,
|
|
88
|
+
}[type];
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Container
|
|
92
|
+
ref={ref}
|
|
93
|
+
type={type}
|
|
94
|
+
textColor={light.colorText}
|
|
95
|
+
backgroundColor={backgroundColor}
|
|
96
|
+
transitionDelay={light.transitionDelay}
|
|
97
|
+
role='alert'
|
|
98
|
+
>
|
|
99
|
+
<AlertIcon type={type} />
|
|
100
|
+
<Text>{text}</Text>
|
|
101
|
+
</Container>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
Message.displayName = 'Message';
|
|
107
|
+
|
|
108
|
+
export default Message;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { AlertProps } from '../Alert';
|
|
4
|
+
|
|
5
|
+
import Message, { MESSAGE_DURATION_MS } from './Message';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
containerStyles,
|
|
9
|
+
messageContainerStyles,
|
|
10
|
+
setStylesToHtmlElement,
|
|
11
|
+
} from './styles';
|
|
12
|
+
|
|
13
|
+
let containerElement: HTMLElement | null;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates the container for storing messages.
|
|
17
|
+
*/
|
|
18
|
+
const getContainer = () => {
|
|
19
|
+
if (!containerElement) {
|
|
20
|
+
containerElement = document.createElement('div');
|
|
21
|
+
setStylesToHtmlElement(containerElement, containerStyles);
|
|
22
|
+
document.body.appendChild(containerElement);
|
|
23
|
+
}
|
|
24
|
+
return containerElement;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Delete the container if there are no more messages in it.
|
|
29
|
+
*/
|
|
30
|
+
const deleteContainerIfNoChildNodes = () => {
|
|
31
|
+
if (!containerElement || containerElement.hasChildNodes()) return;
|
|
32
|
+
document.body.removeChild(containerElement);
|
|
33
|
+
containerElement = null;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Renders a new message.
|
|
38
|
+
*/
|
|
39
|
+
const send = (type: AlertProps['type'], text: string) => {
|
|
40
|
+
// Create a new container for the message
|
|
41
|
+
const container = getContainer();
|
|
42
|
+
const messageContainer = document.createElement('div');
|
|
43
|
+
setStylesToHtmlElement(messageContainer, messageContainerStyles);
|
|
44
|
+
container.appendChild(messageContainer);
|
|
45
|
+
|
|
46
|
+
// Render the message element
|
|
47
|
+
const messageElement = <Message type={type} text={text} />;
|
|
48
|
+
ReactDOM.render(messageElement, messageContainer);
|
|
49
|
+
|
|
50
|
+
// Delete the message container after N ms
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
ReactDOM.unmountComponentAtNode(messageContainer);
|
|
53
|
+
container.removeChild(messageContainer);
|
|
54
|
+
deleteContainerIfNoChildNodes();
|
|
55
|
+
}, MESSAGE_DURATION_MS);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const message: Record<AlertProps['type'], (text: string) => void> = {
|
|
59
|
+
info: (text) => send('info', text),
|
|
60
|
+
success: (text) => send('success', text),
|
|
61
|
+
error: (text) => send('error', text),
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default message;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const containerStyles: Partial<CSSStyleDeclaration> = {
|
|
2
|
+
position: 'fixed',
|
|
3
|
+
top: '0',
|
|
4
|
+
left: '0',
|
|
5
|
+
right: '0',
|
|
6
|
+
zIndex: '1001',
|
|
7
|
+
pointerEvents: 'none',
|
|
8
|
+
display: 'flex',
|
|
9
|
+
flexDirection: 'column',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const messageContainerStyles: Partial<CSSStyleDeclaration> = {
|
|
13
|
+
display: 'flex',
|
|
14
|
+
justifyContent: 'center',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const setStylesToHtmlElement = (
|
|
18
|
+
element: HTMLElement,
|
|
19
|
+
styles: Partial<CSSStyleDeclaration>
|
|
20
|
+
): void => {
|
|
21
|
+
Object.entries(styles).forEach(([key, value]) => {
|
|
22
|
+
// eslint-disable-next-line no-param-reassign
|
|
23
|
+
element.style[key] = value;
|
|
24
|
+
});
|
|
25
|
+
};
|