@fibery/ui-kit 1.20.0 → 1.20.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/ui-kit",
3
- "version": "1.20.0",
3
+ "version": "1.20.1",
4
4
  "main": "index.ts",
5
5
  "private": false,
6
6
  "files": [
@@ -25,6 +25,7 @@
25
25
  "src/button",
26
26
  "src/emoji-picker/**/*.ts*",
27
27
  "src/toast/**/*.ts*",
28
+ "src/lists/**/*.ts*",
28
29
  "src/a11y-color.ts"
29
30
  ],
30
31
  "license": "UNLICENSED",
@@ -67,9 +68,9 @@
67
68
  "react-windowed-select": "5.0.0",
68
69
  "screenfull": "6.0.1",
69
70
  "ua-parser-js": "0.7.24",
71
+ "@fibery/emoji-data": "2.2.1",
70
72
  "@fibery/helpers": "1.2.0",
71
- "@fibery/react": "1.3.0",
72
- "@fibery/emoji-data": "2.2.1"
73
+ "@fibery/react": "1.3.0"
73
74
  },
74
75
  "peerDependencies": {
75
76
  "react": "^18.2.0",
@@ -0,0 +1,139 @@
1
+ import {styled} from "@linaria/react";
2
+ import {forwardRef, HTMLAttributes, PropsWithChildren, ReactNode} from "react";
3
+ import {border, space, textStyles, themeVars} from "../design-system";
4
+ import {css, cx} from "@linaria/core";
5
+
6
+ export interface ListItemGeneralProps extends HTMLAttributes<HTMLDivElement> {
7
+ className?: string;
8
+ selected?: boolean;
9
+ done?: boolean;
10
+ focused?: boolean;
11
+ hovered?: boolean;
12
+ }
13
+ const NATUAL_HOVER_CLASS = "natural-hover";
14
+ const NATUAL_FOCUS_CLASS = "natural-focus";
15
+ const NATURAL_HOVER = `&.${NATUAL_HOVER_CLASS}:hover`;
16
+ const NATURAL_FOCUS = `&.${NATUAL_FOCUS_CLASS}:focus`;
17
+
18
+ const ListItemGeneralRoot = styled.div`
19
+ max-width: 100%;
20
+ flex-basis: 100%;
21
+ display: flex;
22
+ cursor: default;
23
+ align-items: center;
24
+ align-content: center;
25
+ padding: 0 ${space.s4}px;
26
+ column-gap: ${space.s4}px;
27
+ ${{...textStyles.regular}};
28
+ color: ${themeVars.textColor};
29
+ border-radius: ${border.radius6}px;
30
+ background-color: ${themeVars.colorBgListItemGeneral};
31
+ transition: background-color;
32
+ ${NATURAL_HOVER},
33
+ &.hover {
34
+ cursor: pointer;
35
+ background-color: ${themeVars.colorBgListItemGeneralHover};
36
+ }
37
+
38
+ ${NATURAL_FOCUS}, &.focus {
39
+ background-color: ${themeVars.colorBgListItemGeneralFocus};
40
+ ${NATURAL_HOVER},
41
+ &.hover {
42
+ background-color: ${themeVars.colorBgListItemGeneralFocus};
43
+ }
44
+ }
45
+ &.done {
46
+ cursor: not-allowed;
47
+ color: ${themeVars.colorTextListItemGeneralDisabled};
48
+ background-color: ${themeVars.colorBgListItemGeneralDisabled};
49
+ ${NATURAL_HOVER},
50
+ &.hover,
51
+ ${NATURAL_FOCUS},
52
+ &.focus {
53
+ background-color: ${themeVars.colorBgListItemGeneralDisabled};
54
+ }
55
+ > * {
56
+ opacity: ${themeVars.opacityListItemGeneralDisabled};
57
+ }
58
+ }
59
+ &.selected {
60
+ cursor: default;
61
+ background-color: ${themeVars.colorBgListItemGeneralSelected};
62
+ ${NATURAL_HOVER},
63
+ &.hover {
64
+ background-color: ${themeVars.colorBgListItemGeneralSelectedHover};
65
+ }
66
+ ${NATURAL_FOCUS},
67
+ &.focus {
68
+ background-color: ${themeVars.colorBgListItemGeneralSelectedFocus};
69
+ }
70
+ }
71
+ `;
72
+
73
+ /**
74
+ * This should be responsible for all flat list items existing in UI in Fibery. Options, action menus and etc.
75
+ * You can enforce it's state with props focused, hovered, selected, done (use it for disabled too)
76
+ */
77
+ export const ListItem = forwardRef<HTMLDivElement, ListItemGeneralProps>(
78
+ ({selected, focused, hovered, done, className, children, ...rest}, ref) => {
79
+ return (
80
+ <ListItemGeneralRoot
81
+ {...rest}
82
+ className={cx(
83
+ className,
84
+ hovered === undefined && NATUAL_HOVER_CLASS,
85
+ focused === undefined && NATUAL_FOCUS_CLASS,
86
+ focused && "focus",
87
+ hovered && "hover",
88
+ selected && "selected",
89
+ done && "done"
90
+ )}
91
+ ref={ref}
92
+ >
93
+ {children}
94
+ </ListItemGeneralRoot>
95
+ );
96
+ }
97
+ );
98
+
99
+ export interface ListItemCompoundLayoutProps extends PropsWithChildren<HTMLAttributes<HTMLDivElement>> {
100
+ className?: string;
101
+ before?: ReactNode;
102
+ after?: ReactNode;
103
+ contentClassName?: string;
104
+ beforeClassName?: string;
105
+ afterClassName?: string;
106
+ }
107
+
108
+ const ListItemCompoundLayoutRoot = css`
109
+ flex-basis: 100%;
110
+ display: flex;
111
+ justify-content: stretch;
112
+ align-items: center;
113
+ overflow: hidden;
114
+ `;
115
+ const ListItemCompoundLayoutContainerStyle = css`
116
+ display: flex; // never new line
117
+ align-items: center;
118
+ `;
119
+ const ListItemCompoundLayoutContentStyle = css`
120
+ ${{...textStyles.regular}}
121
+ overflow: hidden;
122
+ text-overflow: ellipsis;
123
+ padding: 0 0 0 ${space.s4}px;
124
+ white-space: nowrap;
125
+ min-width: 0; // allows ellipsis in flex contexts :)
126
+ max-width: 100%;
127
+ width: 100%;
128
+ `;
129
+ export const ListItemLayout = forwardRef<HTMLDivElement, ListItemCompoundLayoutProps>(
130
+ ({before, after, className, afterClassName, beforeClassName, contentClassName, children, ...rest}, ref) => {
131
+ return (
132
+ <div {...rest} ref={ref} className={cx(className, ListItemCompoundLayoutRoot)}>
133
+ {before ? <div className={cx(ListItemCompoundLayoutContainerStyle, beforeClassName)}>{before}</div> : null}
134
+ <div className={cx(ListItemCompoundLayoutContentStyle, contentClassName)}>{children}</div>
135
+ {after ? <div className={cx(ListItemCompoundLayoutContainerStyle, afterClassName)}>{after}</div> : null}
136
+ </div>
137
+ );
138
+ }
139
+ );