@qoretechnologies/reqore 0.44.0 → 0.45.0
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 +1 -1
- package/tests.json +1 -1
- package/.eslintrc.js +0 -40
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/ISSUE_TEMPLATE/new-component.md +0 -20
- package/.github/ISSUE_TEMPLATE/visual-bug-report.md +0 -38
- package/.github/workflows/beta_release.yml +0 -100
- package/.github/workflows/tests.yml +0 -84
- package/.gitpod.yml +0 -11
- package/.jest-test-results.json +0 -1
- package/.prettierrc +0 -7
- package/.vscode/settings.json +0 -0
- package/__tests__/breadcrumbs.test.tsx +0 -75
- package/__tests__/button.test.tsx +0 -218
- package/__tests__/checkbox.test.tsx +0 -45
- package/__tests__/collection.test.tsx +0 -243
- package/__tests__/containers/paging.test.tsx +0 -138
- package/__tests__/control_group.test.tsx +0 -32
- package/__tests__/drawer.test.tsx +0 -140
- package/__tests__/dropdown.test.tsx +0 -381
- package/__tests__/effect.test.tsx +0 -70
- package/__tests__/heading.test.tsx +0 -58
- package/__tests__/helpers/colors.test.tsx +0 -18
- package/__tests__/helpers/table.test.tsx +0 -67
- package/__tests__/hooks/useLatestZIndex.test.tsx +0 -10
- package/__tests__/hooks/useReqorePaging.test.tsx +0 -271
- package/__tests__/hooks/useTheme.test.tsx +0 -31
- package/__tests__/icon.test.tsx +0 -53
- package/__tests__/input.test.tsx +0 -482
- package/__tests__/layout.test.tsx +0 -37
- package/__tests__/menu.test.tsx +0 -65
- package/__tests__/messages.test.tsx +0 -79
- package/__tests__/modal.test.tsx +0 -204
- package/__tests__/multiselect.test.tsx +0 -458
- package/__tests__/navbar.test.tsx +0 -31
- package/__tests__/notifications.test.tsx +0 -178
- package/__tests__/pagination.test.tsx +0 -437
- package/__tests__/panel.test.tsx +0 -243
- package/__tests__/popover.test.tsx +0 -282
- package/__tests__/radiogroup.test.tsx +0 -47
- package/__tests__/setup.js +0 -8
- package/__tests__/stories/Collection.stories.tsx +0 -0
- package/__tests__/table.test.tsx +0 -647
- package/__tests__/tabs.test.tsx +0 -321
- package/__tests__/tag.test.tsx +0 -160
- package/__tests__/textarea.test.tsx +0 -467
- package/__tests__/timeAgo.test.tsx +0 -27
- package/__tests__/tree.test.tsx +0 -58
- package/build-storybook.log +0 -491
- package/chromatic.config.json +0 -1
- package/icons.ts +0 -1
- package/migration-storybook.log +0 -56
- package/public/logo-dark.png +0 -0
- package/public/logo.png +0 -0
- package/public/q-symbol-small.png +0 -0
- package/public/q-symbol.png +0 -0
- package/public/qoreLogo-dark.png +0 -0
- package/public/qoreLogo.png +0 -0
- package/src/components/Breadcrumbs/index.tsx +0 -254
- package/src/components/Breadcrumbs/item.tsx +0 -44
- package/src/components/Button/index.tsx +0 -633
- package/src/components/Checkbox/index.tsx +0 -388
- package/src/components/Collection/index.tsx +0 -426
- package/src/components/Collection/item.tsx +0 -267
- package/src/components/Columns/column.tsx +0 -27
- package/src/components/Columns/index.tsx +0 -41
- package/src/components/Comment/index.tsx +0 -141
- package/src/components/CommentFeed/index.tsx +0 -34
- package/src/components/Content/index.tsx +0 -34
- package/src/components/Content/wrapper.tsx +0 -36
- package/src/components/ControlGroup/index.tsx +0 -523
- package/src/components/DatePicker/index.tsx +0 -347
- package/src/components/Drawer/backdrop.tsx +0 -54
- package/src/components/Drawer/index.tsx +0 -365
- package/src/components/Dropdown/index.tsx +0 -153
- package/src/components/Dropdown/item.tsx +0 -33
- package/src/components/Dropdown/list.tsx +0 -222
- package/src/components/Effect/index.tsx +0 -464
- package/src/components/ExportModal/index.tsx +0 -99
- package/src/components/Header/index.tsx +0 -81
- package/src/components/Icon/index.tsx +0 -184
- package/src/components/Input/index.tsx +0 -295
- package/src/components/InputClearButton/index.tsx +0 -59
- package/src/components/InternalPopover/index.tsx +0 -303
- package/src/components/KeyValueTable/index.tsx +0 -192
- package/src/components/Label/index.tsx +0 -10
- package/src/components/Layout/content.tsx +0 -31
- package/src/components/Layout/index.tsx +0 -55
- package/src/components/Menu/divider.tsx +0 -92
- package/src/components/Menu/index.tsx +0 -141
- package/src/components/Menu/item.tsx +0 -137
- package/src/components/Menu/section.tsx +0 -81
- package/src/components/Message/index.tsx +0 -220
- package/src/components/Modal/index.tsx +0 -26
- package/src/components/MultiSelect/index.tsx +0 -288
- package/src/components/Navbar/divider.tsx +0 -50
- package/src/components/Navbar/group.tsx +0 -53
- package/src/components/Navbar/index.tsx +0 -82
- package/src/components/Navbar/item.tsx +0 -92
- package/src/components/Notifications/index.tsx +0 -57
- package/src/components/Notifications/notification.tsx +0 -362
- package/src/components/Paging/index.tsx +0 -321
- package/src/components/Panel/LabelEditor.tsx +0 -67
- package/src/components/Panel/NonResponsiveActions.tsx +0 -79
- package/src/components/Panel/__screenshots__/linux/panel-SomePanel.png +0 -0
- package/src/components/Panel/index.tsx +0 -912
- package/src/components/Panel/panel.screenshot.tsx +0 -29
- package/src/components/Paragraph/index.tsx +0 -43
- package/src/components/Popover/index.tsx +0 -68
- package/src/components/RadioGroup/index.tsx +0 -71
- package/src/components/Slider/index.tsx +0 -358
- package/src/components/Spacer/index.tsx +0 -142
- package/src/components/Spinner/index.tsx +0 -74
- package/src/components/Table/body.tsx +0 -109
- package/src/components/Table/cell.tsx +0 -136
- package/src/components/Table/header.tsx +0 -236
- package/src/components/Table/headerCell.tsx +0 -203
- package/src/components/Table/helpers.ts +0 -308
- package/src/components/Table/index.tsx +0 -797
- package/src/components/Table/row.tsx +0 -288
- package/src/components/Table/value.tsx +0 -28
- package/src/components/Tabs/content.tsx +0 -68
- package/src/components/Tabs/index.tsx +0 -124
- package/src/components/Tabs/item.tsx +0 -198
- package/src/components/Tabs/list.tsx +0 -381
- package/src/components/Tag/group.tsx +0 -73
- package/src/components/Tag/index.tsx +0 -463
- package/src/components/Textarea/index.tsx +0 -277
- package/src/components/TimeAgo/index.tsx +0 -15
- package/src/components/Tree/index.tsx +0 -271
- package/src/constants/animations.ts +0 -9
- package/src/constants/colors.ts +0 -13
- package/src/constants/paging.ts +0 -93
- package/src/constants/sizes.ts +0 -185
- package/src/constants/theme.ts +0 -122
- package/src/containers/Paging.tsx +0 -136
- package/src/containers/PopoverProvider.tsx +0 -124
- package/src/containers/ReqoreProvider.tsx +0 -289
- package/src/containers/ThemeProvider.tsx +0 -12
- package/src/containers/UIProvider.tsx +0 -101
- package/src/context/PopoverContext.tsx +0 -11
- package/src/context/ReqoreContext.tsx +0 -47
- package/src/context/ThemeContext.tsx +0 -4
- package/src/helpers/animations.ts +0 -13
- package/src/helpers/colors.ts +0 -335
- package/src/helpers/time.ts +0 -21
- package/src/helpers/utils.ts +0 -152
- package/src/hooks/useAutoFocus.ts +0 -106
- package/src/hooks/useCloneThroughFragments.ts +0 -39
- package/src/hooks/useCombinedRefs.ts +0 -26
- package/src/hooks/useLatestZIndex.ts +0 -13
- package/src/hooks/useOutsideClick.ts +0 -29
- package/src/hooks/usePaging.ts +0 -128
- package/src/hooks/usePopover.tsx +0 -220
- package/src/hooks/useQueryWithDelay.ts +0 -30
- package/src/hooks/useReqore.ts +0 -12
- package/src/hooks/useReqoreContext.ts +0 -16
- package/src/hooks/useReqoreEffect.ts +0 -49
- package/src/hooks/useTextareaAutoSize.ts +0 -22
- package/src/hooks/useTheme.ts +0 -48
- package/src/hooks/useTooltip.ts +0 -40
- package/src/hooks/useWhyDidYouUpdate.ts +0 -32
- package/src/icons.json +0 -2295
- package/src/index.tsx +0 -80
- package/src/mock/breadcrumbs.ts +0 -146
- package/src/mock/collectionData.tsx +0 -380
- package/src/mock/data.json +0 -11000
- package/src/mock/icons.ts +0 -32
- package/src/mock/menu.ts +0 -93
- package/src/mock/multiSelect.ts +0 -71
- package/src/mock/object.json +0 -317
- package/src/mock/styleMock.js +0 -1
- package/src/mock/tableData.ts +0 -64
- package/src/stories/Breadcrumbs/Breadcrumbs.stories.tsx +0 -27
- package/src/stories/Button/Button.stories.tsx +0 -405
- package/src/stories/Checkbox/Checkbox.stories.tsx +0 -75
- package/src/stories/Collection/Collection.stories.tsx +0 -317
- package/src/stories/Columns/Columns.stories.tsx +0 -158
- package/src/stories/Comment/Comment.stories.tsx +0 -136
- package/src/stories/ControlGroup/ControlGroup.stories.tsx +0 -399
- package/src/stories/DatePicker/DatePicker.stories.tsx +0 -348
- package/src/stories/Drawer/Drawer.stories.tsx +0 -294
- package/src/stories/Dropdown/Dropdown.stories.tsx +0 -375
- package/src/stories/Dropdown/DropdownTests.stories.tsx +0 -111
- package/src/stories/ExportModal/ExportModal.stories.tsx +0 -18
- package/src/stories/Header/Header.stories.tsx +0 -108
- package/src/stories/Icon/Icon.stories.tsx +0 -162
- package/src/stories/Input/Input.stories.tsx +0 -220
- package/src/stories/KeyValueTable/KeyValueTable.stories.tsx +0 -346
- package/src/stories/Label/Label.stories.tsx +0 -33
- package/src/stories/Menu/Menu.stories.tsx +0 -367
- package/src/stories/Message/Message.stories.tsx +0 -167
- package/src/stories/Modal/Manager.stories.tsx +0 -192
- package/src/stories/Modal/Modal.stories.tsx +0 -252
- package/src/stories/MultiSelect/MultiSelect.stories.tsx +0 -140
- package/src/stories/Navbar/Navbar.stories.tsx +0 -119
- package/src/stories/Notifications/Interactive.stories.tsx +0 -117
- package/src/stories/Notifications/Notification.stories.tsx +0 -216
- package/src/stories/Notifications/Notifications.stories.tsx +0 -81
- package/src/stories/Paging/Paging.stories.tsx +0 -255
- package/src/stories/Panel/Panel.stories.tsx +0 -753
- package/src/stories/Paragraph/Paragraph.stories.tsx +0 -108
- package/src/stories/Popover/Popover.stories.tsx +0 -510
- package/src/stories/RadioGroup/RadioGroup.stories.tsx +0 -212
- package/src/stories/Slider/Slider.stories.tsx +0 -173
- package/src/stories/Spacer/Spacer.stories.tsx +0 -100
- package/src/stories/Spinner/Spinner.stories.tsx +0 -82
- package/src/stories/Table/Table.stories.tsx +0 -571
- package/src/stories/Tabs/Tabs.stories.tsx +0 -346
- package/src/stories/Tag/Tag.stories.tsx +0 -381
- package/src/stories/Tag/TagGroup.stories.tsx +0 -307
- package/src/stories/TextArea/TextArea.stories.tsx +0 -287
- package/src/stories/TextArea/TextAreaTests.stories.tsx +0 -108
- package/src/stories/Tree/Tree.stories.tsx +0 -124
- package/src/stories/Wrapper.tsx +0 -13
- package/src/stories/utils/args.ts +0 -151
- package/src/stories/utils.ts +0 -39
- package/src/styles.ts +0 -124
- package/src/types/global.ts +0 -211
- package/src/types/icons.ts +0 -2272
- package/tsconfig.prod.json +0 -26
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import { size } from 'lodash';
|
|
2
|
-
import React, { memo, useCallback, useEffect, useMemo, useState } from 'react';
|
|
3
|
-
import { TReqorePaginationType } from '../../constants/paging';
|
|
4
|
-
import { PADDING_FROM_SIZE } from '../../constants/sizes';
|
|
5
|
-
import { ReqorePaginationContainer } from '../../containers/Paging';
|
|
6
|
-
import { IReqoreComponent } from '../../types/global';
|
|
7
|
-
import ReqoreButton from '../Button';
|
|
8
|
-
import ReqoreControlGroup from '../ControlGroup';
|
|
9
|
-
import ReqoreInput, { IReqoreInputProps } from '../Input';
|
|
10
|
-
import ReqoreMenu from '../Menu';
|
|
11
|
-
import ReqoreMenuDivider, { IReqoreMenuDividerProps } from '../Menu/divider';
|
|
12
|
-
import { IReqoreMenuItemProps } from '../Menu/item';
|
|
13
|
-
import { ReqoreVerticalSpacer } from '../Spacer';
|
|
14
|
-
import { ReqoreDropdownItem } from './item';
|
|
15
|
-
|
|
16
|
-
export type TDropdownItemOnClick = (item: IReqoreDropdownItem) => void;
|
|
17
|
-
export interface IReqoreDropdownItem
|
|
18
|
-
extends Omit<IReqoreMenuItemProps, 'onClick' | 'onRightIconClick'> {
|
|
19
|
-
value?: any;
|
|
20
|
-
items?: TReqoreDropdownItems;
|
|
21
|
-
onClick?: TDropdownItemOnClick;
|
|
22
|
-
divider?: boolean;
|
|
23
|
-
dividerAlign?: 'left' | 'center' | 'right';
|
|
24
|
-
dividerPadded?: 'top' | 'bottom' | 'both' | 'none';
|
|
25
|
-
line?: boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type TReqoreDropdownItem = IReqoreDropdownItem;
|
|
29
|
-
export type TReqoreDropdownItems = TReqoreDropdownItem[];
|
|
30
|
-
|
|
31
|
-
export interface IReqoreDropdownListProps extends IReqoreComponent {
|
|
32
|
-
items?: TReqoreDropdownItems;
|
|
33
|
-
multiSelect?: boolean;
|
|
34
|
-
listStyle?: React.CSSProperties;
|
|
35
|
-
width?: string;
|
|
36
|
-
height?: string;
|
|
37
|
-
|
|
38
|
-
filterable?: boolean;
|
|
39
|
-
onFilterChange?: (query: string) => void;
|
|
40
|
-
filter?: string | number;
|
|
41
|
-
filterPlaceholder?: string;
|
|
42
|
-
|
|
43
|
-
onItemSelect?: TDropdownItemOnClick;
|
|
44
|
-
inputProps?: IReqoreInputProps;
|
|
45
|
-
scrollToSelected?: boolean;
|
|
46
|
-
paging?: TReqorePaginationType<TReqoreDropdownItem>;
|
|
47
|
-
|
|
48
|
-
_onBackClick?: () => void;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const ReqoreDropdownList = memo(
|
|
52
|
-
({
|
|
53
|
-
items,
|
|
54
|
-
multiSelect,
|
|
55
|
-
listStyle,
|
|
56
|
-
_popoverId,
|
|
57
|
-
filterable,
|
|
58
|
-
width,
|
|
59
|
-
height,
|
|
60
|
-
onItemSelect,
|
|
61
|
-
inputProps,
|
|
62
|
-
scrollToSelected,
|
|
63
|
-
paging,
|
|
64
|
-
onFilterChange,
|
|
65
|
-
filterPlaceholder,
|
|
66
|
-
filter,
|
|
67
|
-
_onBackClick,
|
|
68
|
-
}: IReqoreDropdownListProps) => {
|
|
69
|
-
const [_items, setItems] = useState<TReqoreDropdownItems>(items);
|
|
70
|
-
const [query, setQuery] = useState<string | number>(onFilterChange ? '' : filter || '');
|
|
71
|
-
const [menuRef, setMenuRef] = useState<HTMLDivElement>(undefined);
|
|
72
|
-
const [selectedItem, setSelectedItem] = useState<IReqoreDropdownItem>(undefined);
|
|
73
|
-
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
setItems(items);
|
|
76
|
-
}, [items]);
|
|
77
|
-
|
|
78
|
-
const filteredItems: TReqoreDropdownItems = useMemo(() => {
|
|
79
|
-
if (!filterable || query === '') {
|
|
80
|
-
return _items;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return _items.filter((item) => {
|
|
84
|
-
if (item.divider) {
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const text: string | undefined = item.label || item.value || item.children;
|
|
89
|
-
|
|
90
|
-
if (!text) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return text.toString().toLowerCase().indexOf(query.toString().toLowerCase()) !== -1;
|
|
95
|
-
});
|
|
96
|
-
}, [items, query, _items]);
|
|
97
|
-
|
|
98
|
-
const handleQueryChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
99
|
-
if (onFilterChange) {
|
|
100
|
-
onFilterChange(event.target.value);
|
|
101
|
-
} else {
|
|
102
|
-
setQuery(event.target.value);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const handleItemClick = useCallback(
|
|
107
|
-
(item: IReqoreDropdownItem): void => {
|
|
108
|
-
if (size(item.items)) {
|
|
109
|
-
setSelectedItem(item);
|
|
110
|
-
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (item.onClick) {
|
|
115
|
-
item.onClick(item);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (onItemSelect) {
|
|
119
|
-
onItemSelect(item);
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
[onItemSelect, selectedItem]
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
if (selectedItem) {
|
|
126
|
-
return (
|
|
127
|
-
<ReqoreDropdownList
|
|
128
|
-
{...{
|
|
129
|
-
items: selectedItem.items,
|
|
130
|
-
multiSelect,
|
|
131
|
-
listStyle,
|
|
132
|
-
_popoverId,
|
|
133
|
-
filterable,
|
|
134
|
-
width,
|
|
135
|
-
height,
|
|
136
|
-
onItemSelect,
|
|
137
|
-
inputProps,
|
|
138
|
-
scrollToSelected,
|
|
139
|
-
paging,
|
|
140
|
-
onFilterChange,
|
|
141
|
-
filterPlaceholder,
|
|
142
|
-
filter,
|
|
143
|
-
_onBackClick: () => setSelectedItem(undefined),
|
|
144
|
-
}}
|
|
145
|
-
/>
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return (
|
|
150
|
-
<>
|
|
151
|
-
{filterable || _onBackClick ? (
|
|
152
|
-
<>
|
|
153
|
-
<ReqoreControlGroup fluid>
|
|
154
|
-
{_onBackClick && (
|
|
155
|
-
<ReqoreButton
|
|
156
|
-
icon='ArrowLeftSLine'
|
|
157
|
-
fluid={!filterable}
|
|
158
|
-
fixed={filterable}
|
|
159
|
-
onClick={_onBackClick}
|
|
160
|
-
className='reqore-dropdown-back-button'
|
|
161
|
-
/>
|
|
162
|
-
)}
|
|
163
|
-
{filterable && (
|
|
164
|
-
<ReqoreInput
|
|
165
|
-
value={onFilterChange ? filter : query}
|
|
166
|
-
icon='SearchLine'
|
|
167
|
-
onChange={handleQueryChange}
|
|
168
|
-
placeholder={
|
|
169
|
-
filterPlaceholder ||
|
|
170
|
-
`Search ${size(_items.filter((item) => !item.divider))} items...`
|
|
171
|
-
}
|
|
172
|
-
onClearClick={() => (onFilterChange ? onFilterChange('') : setQuery(''))}
|
|
173
|
-
{...inputProps}
|
|
174
|
-
/>
|
|
175
|
-
)}
|
|
176
|
-
</ReqoreControlGroup>
|
|
177
|
-
<ReqoreVerticalSpacer height={PADDING_FROM_SIZE.normal} />
|
|
178
|
-
</>
|
|
179
|
-
) : null}
|
|
180
|
-
<ReqorePaginationContainer type={paging} items={filteredItems} scrollContainer={menuRef}>
|
|
181
|
-
{(finalItems, Controls, { includeBottomControls }) => (
|
|
182
|
-
<ReqoreMenu
|
|
183
|
-
_insidePopover={!multiSelect}
|
|
184
|
-
_popoverId={_popoverId}
|
|
185
|
-
style={listStyle}
|
|
186
|
-
width={width}
|
|
187
|
-
maxHeight={height || '300px'}
|
|
188
|
-
padded={false}
|
|
189
|
-
ref={setMenuRef}
|
|
190
|
-
>
|
|
191
|
-
{finalItems.map(
|
|
192
|
-
(
|
|
193
|
-
{ dividerAlign, dividerPadded, divider, ...item }: IReqoreDropdownItem,
|
|
194
|
-
index: number
|
|
195
|
-
) =>
|
|
196
|
-
divider ? (
|
|
197
|
-
<ReqoreMenuDivider
|
|
198
|
-
key={index}
|
|
199
|
-
{...(item as unknown as IReqoreMenuDividerProps)}
|
|
200
|
-
align={dividerAlign}
|
|
201
|
-
padded={dividerPadded}
|
|
202
|
-
/>
|
|
203
|
-
) : (
|
|
204
|
-
<ReqoreDropdownItem
|
|
205
|
-
key={item.label || item.value || index}
|
|
206
|
-
{...item}
|
|
207
|
-
disabled={'items' in item && !size(item.items) ? true : item.disabled}
|
|
208
|
-
onItemClick={handleItemClick}
|
|
209
|
-
scrollIntoView={scrollToSelected && item.selected && !multiSelect}
|
|
210
|
-
/>
|
|
211
|
-
)
|
|
212
|
-
)}
|
|
213
|
-
{!includeBottomControls && Controls}
|
|
214
|
-
</ReqoreMenu>
|
|
215
|
-
)}
|
|
216
|
-
</ReqorePaginationContainer>
|
|
217
|
-
</>
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
export default ReqoreDropdownList;
|
|
@@ -1,464 +0,0 @@
|
|
|
1
|
-
import { rgba } from 'polished';
|
|
2
|
-
import { HTMLAttributes } from 'react';
|
|
3
|
-
import styled, { css, keyframes } from 'styled-components';
|
|
4
|
-
import { Colors } from '../../constants/colors';
|
|
5
|
-
import { TEXT_FROM_SIZE, TSizes, WEIGHT_TO_NUMBER } from '../../constants/sizes';
|
|
6
|
-
import { IReqoreTheme, TReqoreIntent } from '../../constants/theme';
|
|
7
|
-
import {
|
|
8
|
-
changeLightness,
|
|
9
|
-
createEffectGradient,
|
|
10
|
-
getColorFromMaybeString,
|
|
11
|
-
getGradientMix,
|
|
12
|
-
getReadableColorFrom,
|
|
13
|
-
} from '../../helpers/colors';
|
|
14
|
-
import { isStringSize } from '../../helpers/utils';
|
|
15
|
-
import { IWithReqoreMinimal } from '../../types/global';
|
|
16
|
-
|
|
17
|
-
export type TReqoreEffectColorManipulation = 'darken' | 'lighten';
|
|
18
|
-
export type TReqoreEffectColorManipulationMultiplier =
|
|
19
|
-
| 1
|
|
20
|
-
| 2
|
|
21
|
-
| 3
|
|
22
|
-
| 4
|
|
23
|
-
| 5
|
|
24
|
-
| 6
|
|
25
|
-
| 7
|
|
26
|
-
| 8
|
|
27
|
-
| 9
|
|
28
|
-
| 10
|
|
29
|
-
| 11
|
|
30
|
-
| 12
|
|
31
|
-
| 13
|
|
32
|
-
| 14
|
|
33
|
-
| 15
|
|
34
|
-
| 16
|
|
35
|
-
| 17
|
|
36
|
-
| 18
|
|
37
|
-
| 19
|
|
38
|
-
| 20
|
|
39
|
-
| 21
|
|
40
|
-
| 22
|
|
41
|
-
| 23
|
|
42
|
-
| 24
|
|
43
|
-
| 25
|
|
44
|
-
| 26
|
|
45
|
-
| 27
|
|
46
|
-
| 28
|
|
47
|
-
| 29
|
|
48
|
-
| 30;
|
|
49
|
-
export type TReqoreEffectColorManipulationAlpha =
|
|
50
|
-
| 0
|
|
51
|
-
| 0.1
|
|
52
|
-
| 0.2
|
|
53
|
-
| 0.3
|
|
54
|
-
| 0.4
|
|
55
|
-
| 0.5
|
|
56
|
-
| 0.6
|
|
57
|
-
| 0.7
|
|
58
|
-
| 0.8
|
|
59
|
-
| 0.9
|
|
60
|
-
| 1;
|
|
61
|
-
export type TReqoreHexColor = `#${string}`;
|
|
62
|
-
export type TReqoreRgbColor = `rgb(${number}, ${number}, ${number})`;
|
|
63
|
-
export type TReqoreRgbaColor = `rgba(${number}, ${number}, ${number}, ${string})`;
|
|
64
|
-
export type TReqoreMultiTypeColor = TReqoreHexColor | TReqoreRgbColor | TReqoreRgbaColor;
|
|
65
|
-
export type TReqoreColor = TReqoreHexColor | 'transparent';
|
|
66
|
-
export type TReqoreEffectColor =
|
|
67
|
-
| (TReqoreColor | TReqoreHexColor | 'main' | TReqoreIntent)
|
|
68
|
-
| `${TReqoreIntent | 'main' | TReqoreHexColor}:${TReqoreEffectColorManipulation}`
|
|
69
|
-
| `${
|
|
70
|
-
| TReqoreIntent
|
|
71
|
-
| 'main'
|
|
72
|
-
| TReqoreHexColor}:${TReqoreEffectColorManipulation}:${TReqoreEffectColorManipulationMultiplier}`
|
|
73
|
-
| `${
|
|
74
|
-
| TReqoreIntent
|
|
75
|
-
| 'main'
|
|
76
|
-
| TReqoreHexColor}:${TReqoreEffectColorManipulation}:${TReqoreEffectColorManipulationMultiplier}:${TReqoreEffectColorManipulationAlpha}`;
|
|
77
|
-
export type TReqoreEffectColorList = [
|
|
78
|
-
'main' | TReqoreIntent | TReqoreColor,
|
|
79
|
-
TReqoreEffectColorManipulation | undefined,
|
|
80
|
-
TReqoreEffectColorManipulationMultiplier | undefined,
|
|
81
|
-
TReqoreEffectColorManipulationAlpha | undefined
|
|
82
|
-
];
|
|
83
|
-
export type TReqoreEffectGradientColors =
|
|
84
|
-
| 'main'
|
|
85
|
-
| TReqoreIntent
|
|
86
|
-
| TReqoreHexColor
|
|
87
|
-
| TReqoreEffectGradientColorsObject;
|
|
88
|
-
export type TReqoreEffectGradientColorsObject = Record<number, TReqoreEffectColor>;
|
|
89
|
-
export type TReqoreEffectGradientAnimationTrigger = 'always' | 'hover' | 'active' | 'never';
|
|
90
|
-
|
|
91
|
-
export interface IReqoreEffectFilters {
|
|
92
|
-
grayscale?: boolean;
|
|
93
|
-
blur?: number;
|
|
94
|
-
sepia?: boolean;
|
|
95
|
-
invert?: boolean;
|
|
96
|
-
opacity?: number;
|
|
97
|
-
brightness?: number;
|
|
98
|
-
contrast?: number;
|
|
99
|
-
saturate?: number;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface IReqoreEffect extends IReqoreEffectFilters {
|
|
103
|
-
gradient?: {
|
|
104
|
-
type?: 'linear' | 'radial';
|
|
105
|
-
shape?: 'circle' | 'ellipse';
|
|
106
|
-
colors: TReqoreEffectGradientColors;
|
|
107
|
-
direction?: string;
|
|
108
|
-
borderColor?: TReqoreEffectColor;
|
|
109
|
-
animate?: TReqoreEffectGradientAnimationTrigger;
|
|
110
|
-
animationSpeed?: 1 | 2 | 3 | 4 | 5;
|
|
111
|
-
};
|
|
112
|
-
noWrap?: boolean;
|
|
113
|
-
color?: TReqoreEffectColor;
|
|
114
|
-
spaced?: number;
|
|
115
|
-
weight?: number | 'thin' | 'light' | 'normal' | 'bold' | 'thick';
|
|
116
|
-
uppercase?: boolean;
|
|
117
|
-
textSize?: TSizes | string;
|
|
118
|
-
textAlign?: 'left' | 'center' | 'right';
|
|
119
|
-
glow?: {
|
|
120
|
-
size?: number;
|
|
121
|
-
color: TReqoreEffectColor;
|
|
122
|
-
inset?: boolean;
|
|
123
|
-
blur?: number;
|
|
124
|
-
opacity?: number;
|
|
125
|
-
when?: 'always' | 'hover' | 'focus' | 'active';
|
|
126
|
-
};
|
|
127
|
-
interactive?: boolean;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export interface IReqoreTextEffectProps
|
|
131
|
-
extends HTMLAttributes<HTMLSpanElement>,
|
|
132
|
-
IWithReqoreMinimal {
|
|
133
|
-
children: React.ReactNode;
|
|
134
|
-
effect: IReqoreEffect;
|
|
135
|
-
as?: React.ElementType;
|
|
136
|
-
theme?: IReqoreTheme;
|
|
137
|
-
active?: boolean;
|
|
138
|
-
isText?: boolean;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Animate the gradient
|
|
142
|
-
const StyledGradientKeyframes = keyframes`
|
|
143
|
-
0% {
|
|
144
|
-
background-position: 0% 0%;
|
|
145
|
-
}
|
|
146
|
-
50% {
|
|
147
|
-
background-position: 100% 100%;
|
|
148
|
-
}
|
|
149
|
-
100% {
|
|
150
|
-
background-position: 0% 0%;
|
|
151
|
-
}
|
|
152
|
-
`;
|
|
153
|
-
|
|
154
|
-
export const StyledEffect = styled.span`
|
|
155
|
-
// If gradient was supplied
|
|
156
|
-
${({ effect, theme, minimal, active, isText }: IReqoreTextEffectProps) => {
|
|
157
|
-
if (!effect || !effect.gradient) {
|
|
158
|
-
return undefined;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const gradientType: string = effect.gradient.type || 'linear';
|
|
162
|
-
const gradientColors = createEffectGradient(
|
|
163
|
-
theme,
|
|
164
|
-
effect.gradient.colors,
|
|
165
|
-
minimal ? 0.05 : 0,
|
|
166
|
-
!isText && minimal && !active
|
|
167
|
-
);
|
|
168
|
-
const gradientColorsActive = createEffectGradient(
|
|
169
|
-
theme,
|
|
170
|
-
effect.gradient.colors,
|
|
171
|
-
0.05,
|
|
172
|
-
minimal,
|
|
173
|
-
true
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
const gradientDirectionOrShape =
|
|
177
|
-
gradientType === 'linear'
|
|
178
|
-
? effect.gradient.direction || 'to right'
|
|
179
|
-
: `${effect.gradient.shape || 'circle'} ${effect.gradient.direction || 'at center'}`;
|
|
180
|
-
let gradient = `${gradientType}-gradient(${gradientDirectionOrShape}${gradientColors}) padding-box`;
|
|
181
|
-
let gradientActive = `${gradientType}-gradient(${gradientDirectionOrShape}${gradientColorsActive}) padding-box`;
|
|
182
|
-
|
|
183
|
-
// Determine the text color based on the gradient colors
|
|
184
|
-
let color: TReqoreHexColor | undefined;
|
|
185
|
-
// Only works if there are 2 colors not more and color was not provided
|
|
186
|
-
if (!effect.color) {
|
|
187
|
-
color = getGradientMix(theme, effect.gradient.colors);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
let borderColor: string;
|
|
191
|
-
let borderHoverColor: string;
|
|
192
|
-
|
|
193
|
-
// The user provided a border color - we will use that
|
|
194
|
-
if (effect.gradient.borderColor) {
|
|
195
|
-
borderColor = `${getColorFromMaybeString(theme, effect.gradient.borderColor)}`;
|
|
196
|
-
borderHoverColor = `${changeLightness(
|
|
197
|
-
getColorFromMaybeString(theme, effect.gradient.borderColor),
|
|
198
|
-
0.15
|
|
199
|
-
)}`;
|
|
200
|
-
} else if (!isText) {
|
|
201
|
-
// We will use border-image and create a gradient border
|
|
202
|
-
borderColor = 'transparent';
|
|
203
|
-
borderHoverColor = 'transparent';
|
|
204
|
-
|
|
205
|
-
const borderGradientColors: string = createEffectGradient(
|
|
206
|
-
theme,
|
|
207
|
-
effect.gradient.colors,
|
|
208
|
-
0.15
|
|
209
|
-
);
|
|
210
|
-
const borderGradientColorsActive: string = createEffectGradient(
|
|
211
|
-
theme,
|
|
212
|
-
effect.gradient.colors,
|
|
213
|
-
0.25
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
gradient = `${gradient}, ${gradientType}-gradient(${gradientDirectionOrShape}${borderGradientColors}) border-box`;
|
|
217
|
-
gradientActive = `${gradientActive}, ${gradientType}-gradient(${gradientDirectionOrShape}${borderGradientColorsActive}) border-box`;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return css`
|
|
221
|
-
background: ${active ? gradientActive : gradient};
|
|
222
|
-
border-color: ${borderColor} !important;
|
|
223
|
-
|
|
224
|
-
${color && !minimal
|
|
225
|
-
? css`
|
|
226
|
-
color: ${getReadableColorFrom(getColorFromMaybeString(theme, color), false)} !important;
|
|
227
|
-
&::placeholder {
|
|
228
|
-
color: ${rgba(
|
|
229
|
-
getReadableColorFrom(getColorFromMaybeString(theme, color), false),
|
|
230
|
-
0.7
|
|
231
|
-
)} !important;
|
|
232
|
-
}
|
|
233
|
-
`
|
|
234
|
-
: undefined}
|
|
235
|
-
|
|
236
|
-
${effect.gradient.animate === 'always' || (effect.gradient.animate === 'active' && active)
|
|
237
|
-
? css`
|
|
238
|
-
background-size: 200% 200%;
|
|
239
|
-
animation: ${StyledGradientKeyframes} ${effect.gradient.animationSpeed || 2}s linear
|
|
240
|
-
infinite;
|
|
241
|
-
`
|
|
242
|
-
: undefined}
|
|
243
|
-
|
|
244
|
-
${effect.interactive &&
|
|
245
|
-
css`
|
|
246
|
-
cursor: pointer;
|
|
247
|
-
|
|
248
|
-
&:hover,
|
|
249
|
-
&:focus,
|
|
250
|
-
&:active {
|
|
251
|
-
background: ${gradientActive};
|
|
252
|
-
border-color: ${borderHoverColor} !important;
|
|
253
|
-
|
|
254
|
-
${effect.gradient.animate === 'hover' ||
|
|
255
|
-
(effect.gradient.animate === 'active' && active) ||
|
|
256
|
-
effect.gradient.animate === 'always'
|
|
257
|
-
? css`
|
|
258
|
-
background-size: 200% 200%;
|
|
259
|
-
animation: ${StyledGradientKeyframes} ${effect.gradient.animationSpeed || 2}s linear
|
|
260
|
-
infinite;
|
|
261
|
-
`
|
|
262
|
-
: undefined}
|
|
263
|
-
}
|
|
264
|
-
`}
|
|
265
|
-
`;
|
|
266
|
-
}}
|
|
267
|
-
|
|
268
|
-
${({ effect, theme, isText }: IReqoreTextEffectProps) => {
|
|
269
|
-
if (!effect || !effect.glow) {
|
|
270
|
-
return undefined;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
let glow;
|
|
274
|
-
|
|
275
|
-
if (!isText) {
|
|
276
|
-
glow = css`
|
|
277
|
-
box-shadow: ${effect.glow.inset ? 'inset ' : ''} 0 0 ${effect.glow.blur || 0}px
|
|
278
|
-
${effect.glow.size || 2}px ${getColorFromMaybeString(theme, effect.glow.color)};
|
|
279
|
-
`;
|
|
280
|
-
} else {
|
|
281
|
-
const color = getColorFromMaybeString(
|
|
282
|
-
theme,
|
|
283
|
-
effect.glow.color === 'main' ? 'main:lighten:2' : effect.glow.color
|
|
284
|
-
);
|
|
285
|
-
const blur = effect.glow.blur || 0;
|
|
286
|
-
const opacity = effect.glow.opacity || 1;
|
|
287
|
-
|
|
288
|
-
glow = css`
|
|
289
|
-
color: ${Colors.LIGHT};
|
|
290
|
-
text-shadow: 0 0 ${blur}px ${rgba(color, opacity)},
|
|
291
|
-
0 0 ${blur + 5}px ${rgba(color, opacity)}, 0 0 ${blur + 10}px ${rgba(color, opacity)},
|
|
292
|
-
0 0 1px ${rgba(getReadableColorFrom(color), opacity)},
|
|
293
|
-
0 0 2px ${rgba(getReadableColorFrom(color), opacity)},
|
|
294
|
-
0 0 3px ${rgba(getReadableColorFrom(color), opacity)};
|
|
295
|
-
`;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
if (effect.glow.when === 'always' || !effect.glow.when) {
|
|
299
|
-
return glow;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (effect.glow.when === 'hover') {
|
|
303
|
-
return css`
|
|
304
|
-
&:hover {
|
|
305
|
-
${glow}
|
|
306
|
-
}
|
|
307
|
-
`;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
if (effect.glow.when === 'focus') {
|
|
311
|
-
return css`
|
|
312
|
-
&:focus {
|
|
313
|
-
${glow}
|
|
314
|
-
}
|
|
315
|
-
`;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
if (effect.glow.when === 'active') {
|
|
319
|
-
return css`
|
|
320
|
-
&:active {
|
|
321
|
-
${glow}
|
|
322
|
-
}
|
|
323
|
-
`;
|
|
324
|
-
}
|
|
325
|
-
}}
|
|
326
|
-
|
|
327
|
-
${({ effect }: IReqoreTextEffectProps) =>
|
|
328
|
-
effect && effect.spaced
|
|
329
|
-
? css`
|
|
330
|
-
letter-spacing: ${effect.spaced}px;
|
|
331
|
-
`
|
|
332
|
-
: undefined}
|
|
333
|
-
|
|
334
|
-
${({ effect }: IReqoreTextEffectProps) =>
|
|
335
|
-
effect && effect.uppercase
|
|
336
|
-
? css`
|
|
337
|
-
text-transform: uppercase;
|
|
338
|
-
`
|
|
339
|
-
: undefined}
|
|
340
|
-
|
|
341
|
-
${({ effect }: IReqoreTextEffectProps) => {
|
|
342
|
-
if (!effect || !effect.weight) {
|
|
343
|
-
return undefined;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
const weight =
|
|
347
|
-
typeof effect.weight === 'number' ? effect.weight : WEIGHT_TO_NUMBER[effect.weight];
|
|
348
|
-
|
|
349
|
-
return css`
|
|
350
|
-
font-weight: ${weight} !important;
|
|
351
|
-
`;
|
|
352
|
-
}}
|
|
353
|
-
|
|
354
|
-
${({ effect }: IReqoreTextEffectProps) =>
|
|
355
|
-
effect && effect.noWrap
|
|
356
|
-
? css`
|
|
357
|
-
white-space: nowrap;
|
|
358
|
-
text-overflow: ellipsis;
|
|
359
|
-
overflow: hidden;
|
|
360
|
-
min-width: 30px;
|
|
361
|
-
`
|
|
362
|
-
: undefined}
|
|
363
|
-
|
|
364
|
-
${({ effect, theme }: IReqoreTextEffectProps) =>
|
|
365
|
-
effect && effect.color
|
|
366
|
-
? css`
|
|
367
|
-
color: ${getColorFromMaybeString(theme, effect.color)} !important;
|
|
368
|
-
`
|
|
369
|
-
: undefined}
|
|
370
|
-
|
|
371
|
-
${({ effect }: IReqoreTextEffectProps) =>
|
|
372
|
-
effect && effect.textSize
|
|
373
|
-
? css`
|
|
374
|
-
font-size: ${isStringSize(effect.textSize)
|
|
375
|
-
? `${TEXT_FROM_SIZE[effect.textSize]}px`
|
|
376
|
-
: effect.textSize} !important;
|
|
377
|
-
`
|
|
378
|
-
: undefined}
|
|
379
|
-
|
|
380
|
-
${({ effect }: IReqoreTextEffectProps) =>
|
|
381
|
-
effect && effect.textAlign
|
|
382
|
-
? css`
|
|
383
|
-
width: 100%;
|
|
384
|
-
text-align: ${effect.textAlign};
|
|
385
|
-
`
|
|
386
|
-
: undefined}
|
|
387
|
-
|
|
388
|
-
${({ effect }) =>
|
|
389
|
-
effect &&
|
|
390
|
-
effect.grayscale &&
|
|
391
|
-
css`
|
|
392
|
-
filter: grayscale(100%);
|
|
393
|
-
`};
|
|
394
|
-
${({ effect }) =>
|
|
395
|
-
effect &&
|
|
396
|
-
effect.blur &&
|
|
397
|
-
css`
|
|
398
|
-
filter: blur(${effect.blur}px);
|
|
399
|
-
`};
|
|
400
|
-
${({ effect }) =>
|
|
401
|
-
effect &&
|
|
402
|
-
effect.sepia &&
|
|
403
|
-
css`
|
|
404
|
-
filter: sepia(100%);
|
|
405
|
-
`};
|
|
406
|
-
${({ effect }) =>
|
|
407
|
-
effect &&
|
|
408
|
-
effect.invert &&
|
|
409
|
-
css`
|
|
410
|
-
filter: invert(100%);
|
|
411
|
-
`};
|
|
412
|
-
${({ effect }) =>
|
|
413
|
-
effect && (effect.opacity || effect.opacity === 0)
|
|
414
|
-
? css`
|
|
415
|
-
opacity: ${effect.opacity};
|
|
416
|
-
`
|
|
417
|
-
: undefined};
|
|
418
|
-
${({ effect }) =>
|
|
419
|
-
effect &&
|
|
420
|
-
effect.brightness &&
|
|
421
|
-
css`
|
|
422
|
-
filter: brightness(${effect.brightness}%);
|
|
423
|
-
`};
|
|
424
|
-
${({ effect }) =>
|
|
425
|
-
effect &&
|
|
426
|
-
effect.contrast &&
|
|
427
|
-
css`
|
|
428
|
-
filter: contrast(${effect.contrast}%);
|
|
429
|
-
`};
|
|
430
|
-
${({ effect }) =>
|
|
431
|
-
effect &&
|
|
432
|
-
effect.saturate &&
|
|
433
|
-
css`
|
|
434
|
-
filter: saturate(${effect.saturate}%);
|
|
435
|
-
`};
|
|
436
|
-
`;
|
|
437
|
-
|
|
438
|
-
export const StyledTextEffect = styled(StyledEffect).attrs((props) => ({ ...props, isText: true }))`
|
|
439
|
-
display: inline-block;
|
|
440
|
-
|
|
441
|
-
${({ effect }: IReqoreTextEffectProps) =>
|
|
442
|
-
effect && effect.gradient
|
|
443
|
-
? css`
|
|
444
|
-
-webkit-background-clip: text !important;
|
|
445
|
-
-webkit-text-fill-color: transparent !important;
|
|
446
|
-
`
|
|
447
|
-
: undefined}
|
|
448
|
-
`;
|
|
449
|
-
|
|
450
|
-
export const ReqoreEffect = ({ children, ...rest }: IReqoreTextEffectProps) => {
|
|
451
|
-
return (
|
|
452
|
-
<StyledEffect className='reqore-effect' {...rest}>
|
|
453
|
-
{children}
|
|
454
|
-
</StyledEffect>
|
|
455
|
-
);
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
export const ReqoreTextEffect = ({ children, className, ...rest }: IReqoreTextEffectProps) => {
|
|
459
|
-
return (
|
|
460
|
-
<StyledTextEffect className={`${className || ''} reqore-text-effect`} {...rest}>
|
|
461
|
-
{children}
|
|
462
|
-
</StyledTextEffect>
|
|
463
|
-
);
|
|
464
|
-
};
|