@ndlib/component-library 0.0.37 → 0.0.38

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.
@@ -24,6 +24,7 @@ type ButtonProps = StyledElementProps<HTMLButtonElement, {
24
24
  accessibleLabel?: string;
25
25
  loading?: boolean;
26
26
  disabled?: boolean;
27
+ disableFocusStyles?: boolean;
27
28
  }>;
28
29
  export declare const Button: React.ForwardRefExoticComponent<{
29
30
  sx?: import("../../../theme").StylesProp | undefined;
@@ -40,6 +41,7 @@ export declare const Button: React.ForwardRefExoticComponent<{
40
41
  accessibleLabel?: string | undefined;
41
42
  loading?: boolean | undefined;
42
43
  disabled?: boolean | undefined;
44
+ disableFocusStyles?: boolean | undefined;
43
45
  } & {
44
46
  htmlFor?: string | undefined;
45
47
  } & React.RefAttributes<HTMLButtonElement>>;
@@ -52,7 +52,7 @@ export var BUTTON_TYPE;
52
52
  // ARROW
53
53
  })(BUTTON_TYPE || (BUTTON_TYPE = {}));
54
54
  export const Button = React.forwardRef((_a, ref) => {
55
- var { size: sizeParam, type: typeParam, color, customColor, textColor: textColorParam, primaryIcon, leftIcon, rightIcon, disabled: disabledParam, children, sx, loading } = _a, rest = __rest(_a, ["size", "type", "color", "customColor", "textColor", "primaryIcon", "leftIcon", "rightIcon", "disabled", "children", "sx", "loading"]);
55
+ var { size: sizeParam, type: typeParam, color, customColor, textColor: textColorParam, primaryIcon, leftIcon, rightIcon, disabled: disabledParam, children, sx, loading, disableFocusStyles } = _a, rest = __rest(_a, ["size", "type", "color", "customColor", "textColor", "primaryIcon", "leftIcon", "rightIcon", "disabled", "children", "sx", "loading", "disableFocusStyles"]);
56
56
  const disabled = disabledParam || loading;
57
57
  const theme = useTheme();
58
58
  const { flagInDevelopment } = useEnvironment();
@@ -126,7 +126,7 @@ export const Button = React.forwardRef((_a, ref) => {
126
126
  : undefined;
127
127
  return (_jsxs("button", Object.assign({ ref: ref, tabIndex: disabled ? -1 : 0, disabled: disabled, css: {
128
128
  backgroundColor: customColor,
129
- }, sx: Object.assign(Object.assign({ cursor, bg: customColor ? undefined : bg, color: textColor, px: paddingX, width: width, height: height, border: 'solid 1px', borderRadius: '4px', borderColor, display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'center', ':hover': hoverStyles, ':focus': hoverStyles }, typographyStyles), sx) }, rest, { children: [leftIcon && (_jsx(Icon, { icon: leftIcon, size: typographyStyles.fontSize, sx: { mr: iconMargin[size] }, color: textColor })), _jsx("div", Object.assign({ css: {
129
+ }, sx: Object.assign(Object.assign({ cursor, bg: customColor ? undefined : bg, color: textColor, px: paddingX, width: width, height: height, border: 'solid 1px', borderRadius: '4px', borderColor, display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'center', ':hover': !disableFocusStyles ? hoverStyles : {}, ':focus': !disableFocusStyles ? hoverStyles : {} }, typographyStyles), sx) }, rest, { children: [leftIcon && (_jsx(Icon, { icon: leftIcon, size: typographyStyles.fontSize, sx: { mr: iconMargin[size] }, color: textColor })), _jsx("div", Object.assign({ css: {
130
130
  flexGrow: 1,
131
131
  justifyContent: 'flex-start',
132
132
  textOverflow: 'ellipsis',
@@ -5,3 +5,4 @@ export default meta;
5
5
  type Story = StoryObj<typeof Select>;
6
6
  export declare const Default: Story;
7
7
  export declare const WithLabel: Story;
8
+ export declare const InvertedColors: Story;
@@ -6,6 +6,7 @@ import { useState } from 'react';
6
6
  import { Column } from '../../layout/Column';
7
7
  import { Group } from '../../Group';
8
8
  import { Heading, HEADING_SIZE } from '../../text/Heading';
9
+ import { COLOR } from '../../../../theme/colors';
9
10
  const meta = {
10
11
  title: 'Elements/Fields/Select',
11
12
  component: Select,
@@ -33,3 +34,6 @@ export const Default = {
33
34
  export const WithLabel = {
34
35
  render: () => (_jsx(Column, { children: sizes.map((size) => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, { children: size.label })), _jsx(StatefulSelect, { size: size.size, leftIcon: AppleIcon, sx: { mt: 2 }, label: "Fruit" })] }))) })),
35
36
  };
37
+ export const InvertedColors = {
38
+ render: () => (_jsx(Column, Object.assign({ sx: { backgroundColor: COLOR.BLACK, p: 4 } }, { children: sizes.map((size) => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD, sx: { color: COLOR.WHITE } }, { children: size.label })), _jsx(StatefulSelect, { size: size.size, leftIcon: AppleIcon, sx: { mt: 2 }, inverted: true, label: "Fruit" })] }))) }))),
39
+ };
@@ -1,3 +1,4 @@
1
+ /** @jsxImportSource theme-ui */
1
2
  import React from 'react';
2
3
  import { StyledElementProps } from '../../../../theme';
3
4
  import { INPUT_SIZE } from '../TextInput';
@@ -8,10 +9,11 @@ type SelectProps<Value extends Key, Option extends BasicOption<Value>> = StyledE
8
9
  leftIcon?: React.FC<any>;
9
10
  value: Value;
10
11
  label?: string;
12
+ inverted?: boolean;
11
13
  onSelectOption: (value: Value) => void;
12
14
  options: Option[];
13
15
  renderOption?: RenderOption<Value, Option>;
14
16
  renderOptionLabel?: RenderOptionLabel<Option>;
15
17
  }, string>;
16
- export declare function Select<Value extends Key, Option extends BasicOption<Value>>({ size: sizeParam, placeholder, leftIcon, value, label, onSelectOption, options, renderOption, renderOptionLabel: renderOptionLabelParam, sx, }: SelectProps<Value, Option>): import("react/jsx-runtime").JSX.Element;
18
+ export declare function Select<Value extends Key, Option extends BasicOption<Value>>({ size: sizeParam, placeholder, leftIcon, value, label, onSelectOption, options, renderOption, inverted, renderOptionLabel: renderOptionLabelParam, sx, }: SelectProps<Value, Option>): React.JSX.Element;
17
19
  export {};
@@ -1,4 +1,5 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "theme-ui/jsx-runtime";
2
+ /** @jsxImportSource theme-ui */
2
3
  import { useMemo, useState } from 'react';
3
4
  import _ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
4
5
  import { useFloating, size as sizeMiddleware, offset, autoPlacement, } from '@floating-ui/react';
@@ -30,7 +31,7 @@ const buttonSizeMap = {
30
31
  [INPUT_SIZE.LG]: BUTTON_SIZE.LG,
31
32
  };
32
33
  const DEFAULT_WIDTH = '16rem';
33
- export function Select({ size: sizeParam, placeholder, leftIcon, value, label, onSelectOption, options, renderOption, renderOptionLabel: renderOptionLabelParam, sx, }) {
34
+ export function Select({ size: sizeParam, placeholder, leftIcon, value, label, onSelectOption, options, renderOption, inverted, renderOptionLabel: renderOptionLabelParam, sx, }) {
34
35
  const theme = useTheme();
35
36
  const listboxId = useUniqueHtmlId('select-list-box');
36
37
  const inputId = useUniqueHtmlId('select-input');
@@ -116,16 +117,56 @@ export function Select({ size: sizeParam, placeholder, leftIcon, value, label, o
116
117
  const typography = typographyMap[size];
117
118
  const typographyStyles = getTypographyStyles(typography);
118
119
  const renderOptionLabel = renderOptionLabelParam || defaultRenderOptionLabel;
119
- return (_jsxs(Box, Object.assign({ sx: { position: 'relative' } }, { children: [_jsx(Label, Object.assign({ htmlFor: inputId, typography: labelTypographyMap[size], sx: {
120
+ const focusStyles = {
121
+ boxShadow: inverted ? theme.boxShadow.INVERTED : theme.boxShadow.NORMAL,
122
+ };
123
+ return (_jsxs(Box, Object.assign({ sx: {
124
+ width: DEFAULT_WIDTH,
125
+ position: 'relative',
126
+ borderRadius: '4px',
127
+ backgroundColor: inverted ? COLOR.DARK_GRAY : COLOR.WHITE,
128
+ ':hover fieldset': focusStyles,
129
+ ':focus fieldset': focusStyles,
130
+ } }, { children: [_jsx("fieldset", Object.assign({ sx: {
131
+ textAlign: 'left',
132
+ position: 'absolute',
133
+ inset: '-5px 0px 0px 0px',
134
+ margin: '0px',
135
+ padding: '0px 0.5rem',
136
+ pointerEvents: 'none',
137
+ borderRadius: 'inherit',
138
+ borderStyle: 'solid',
139
+ borderWidth: '1px',
140
+ overflow: 'hidden',
141
+ minWidth: '0%',
142
+ borderColor: inverted ? COLOR.GRAY : COLOR.LIGHT_GRAY,
143
+ zIndex: theme.zIndex.LABEL,
144
+ } }, { children: _jsx("legend", Object.assign({ style: {
145
+ width: 'auto',
146
+ float: 'unset',
147
+ overflow: 'hidden',
148
+ position: 'relative',
149
+ display: 'block',
150
+ padding: '0',
151
+ height: '8px',
152
+ fontSize: '0.75em',
153
+ visibility: 'hidden',
154
+ whiteSpace: 'nowrap',
155
+ } }, { children: label && (_jsx(Label, Object.assign({ standalone: true, sx: {
156
+ px: 1,
157
+ position: 'relative',
158
+ display: 'inline-flex',
159
+ opacity: '0',
160
+ visibility: 'hidden',
161
+ }, typography: labelTypographyMap[size] }, { children: label }))) })) })), _jsx(Label, Object.assign({ htmlFor: inputId, typography: labelTypographyMap[size], sx: {
120
162
  position: 'absolute',
121
- color: COLOR.ND_PROVOST_BLUE,
122
- backgroundColor: COLOR.WHITE,
123
163
  left: '0.5rem',
124
164
  lineHeight: 1,
125
165
  zIndex: theme.zIndex.LABEL,
126
- px: size === INPUT_SIZE.SM ? 1 : 2,
166
+ color: inverted ? COLOR.EXTRA_LIGHT_GRAY : COLOR.PRIMARY,
167
+ px: 1,
127
168
  top: labelOffsetMap[size],
128
- } }, { children: label })), _jsx(Button, Object.assign({ ref: refs.setReference,
169
+ } }, { children: label })), _jsx(Button, Object.assign({ ref: refs.setReference, disableFocusStyles: true,
129
170
  // A11y attributes
130
171
  role: "combobox", "aria-controls": listboxId, "aria-expanded": isOpen, "aria-autocomplete": "none", "aria-activedescendant": isOpen && stagedOptionValue
131
172
  ? getOptionId(stagedOptionValue)
@@ -138,14 +179,15 @@ export function Select({ size: sizeParam, placeholder, leftIcon, value, label, o
138
179
  else {
139
180
  close();
140
181
  }
141
- }, sx: Object.assign(Object.assign({ height, width: DEFAULT_WIDTH, border: 'solid 1px', borderColor: COLOR.GRAY, borderRadius: '4px', flexDirection: 'row', alignItems: 'center', position: 'relative', ':hover': {
142
- boxShadow: theme.boxShadow.NORMAL,
143
- }, ':focus': {
144
- boxShadow: theme.boxShadow.NORMAL,
145
- } }, typographyStyles), sx), leftIcon: leftIcon, rightIcon: ArrowDropDownIcon }, { children: currentOption ? renderOptionLabel(currentOption) : placeholder })), isOpen && (_jsx(ListBox, { id: listboxId, options: options, selected: value, focused: stagedOptionValue, selectOption: (option) => {
182
+ }, color: inverted ? COLOR.EXTRA_LIGHT_GRAY : COLOR.TEXT, sx: Object.assign(Object.assign({ height, width: '100%', border: 'solid 0px',
183
+ // borderColor: COLOR.GRAY,
184
+ // borderRadius: '4px',
185
+ flexDirection: 'row', alignItems: 'center', position: 'relative', zIndex: theme.zIndex.NORMAL, background: 'none' }, typographyStyles), sx), leftIcon: leftIcon, rightIcon: ArrowDropDownIcon }, { children: currentOption ? renderOptionLabel(currentOption) : placeholder })), isOpen && (_jsx(ListBox, { id: listboxId, options: options, selected: value, focused: stagedOptionValue, selectOption: (option) => {
146
186
  onSelectOption && onSelectOption(option.value);
147
187
  close();
148
188
  }, ref: refs.setFloating, renderOption: renderOption, sx: {
149
189
  zIndex: theme.zIndex.DROPDOWN,
150
- }, style: Object.assign(Object.assign({ minWidth: dropdownMinWidth }, floatingStyles), { zIndex: 1 }) }))] })));
190
+ }, style: Object.assign(Object.assign({ minWidth: dropdownMinWidth }, floatingStyles), { boxShadow: inverted
191
+ ? theme.boxShadow.INVERTED
192
+ : theme.boxShadow.NORMAL }) }))] })));
151
193
  }
@@ -5,3 +5,4 @@ export default meta;
5
5
  type Story = StoryObj<typeof TextInput>;
6
6
  export declare const Default: Story;
7
7
  export declare const WithLabel: Story;
8
+ export declare const Inverted: Story;
@@ -5,6 +5,7 @@ import { useState } from 'react';
5
5
  import { Column } from '../../layout/Column';
6
6
  import { Group } from '../../Group';
7
7
  import { Heading, HEADING_SIZE } from '../../text/Heading';
8
+ import { COLOR } from '../../../../theme/colors';
8
9
  const meta = {
9
10
  title: 'Elements/Fields/TextInput',
10
11
  component: TextInput,
@@ -24,5 +25,8 @@ export const Default = {
24
25
  render: () => (_jsx(Column, { children: sizes.map((size) => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, { children: size.label })), _jsx(StatefulInput, { size: size.size, leftIcon: SearchIcon, placeholder: "Placeholder", sx: { mt: 2 } })] }))) })),
25
26
  };
26
27
  export const WithLabel = {
27
- render: () => (_jsx(Column, { children: sizes.map((size) => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, { children: size.label })), _jsx(StatefulInput, { size: size.size, leftIcon: SearchIcon, label: "Search", sx: { mt: 2 } })] }))) })),
28
+ render: () => (_jsx(Column, { children: sizes.map((size) => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, { children: size.label })), _jsx(StatefulInput, { size: size.size, leftIcon: SearchIcon, label: "Search", placeholder: "Placeholder", sx: { mt: 2 } })] }))) })),
29
+ };
30
+ export const Inverted = {
31
+ render: () => (_jsx(Column, Object.assign({ sx: { backgroundColor: COLOR.BLACK, p: 2 } }, { children: sizes.map((size) => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD, sx: { color: COLOR.WHITE } }, { children: size.label })), _jsx(StatefulInput, { size: size.size, leftIcon: SearchIcon, placeholder: "Placeholder", label: "Search", inverted: true, sx: { mt: 2 } })] }))) }))),
28
32
  };
@@ -21,6 +21,7 @@ export type TextInputProps = StyledElementProps<HTMLInputElement, {
21
21
  size?: INPUT_SIZE;
22
22
  leftIcon?: React.FC<any>;
23
23
  inline?: boolean;
24
+ inverted?: boolean;
24
25
  label?: string;
25
26
  value: string;
26
27
  onChange?: (value: string) => void;
@@ -33,6 +34,7 @@ export declare const TextInput: React.ForwardRefExoticComponent<{
33
34
  size?: INPUT_SIZE | undefined;
34
35
  leftIcon?: React.FC<any> | undefined;
35
36
  inline?: boolean | undefined;
37
+ inverted?: boolean | undefined;
36
38
  label?: string | undefined;
37
39
  value: string;
38
40
  onChange?: ((value: string) => void) | undefined;
@@ -50,7 +50,7 @@ const defaultHeight = {
50
50
  [INPUT_SIZE.LG]: '3rem',
51
51
  };
52
52
  export const TextInput = React.forwardRef((_a, ref) => {
53
- var { value, label, onChange, onChangeRaw, onClick, inline, size: sizeParam, leftIcon, sx } = _a, rest = __rest(_a, ["value", "label", "onChange", "onChangeRaw", "onClick", "inline", "size", "leftIcon", "sx"]);
53
+ var { value, label, onChange, onChangeRaw, onClick, inline, inverted, size: sizeParam, leftIcon, sx } = _a, rest = __rest(_a, ["value", "label", "onChange", "onChangeRaw", "onClick", "inline", "inverted", "size", "leftIcon", "sx"]);
54
54
  const id = useUniqueHtmlId('text-input');
55
55
  const theme = useTheme();
56
56
  const size = sizeParam || INPUT_SIZE.MD;
@@ -59,27 +59,58 @@ export const TextInput = React.forwardRef((_a, ref) => {
59
59
  const height = defaultHeight[size];
60
60
  const typography = typographyMap[size];
61
61
  const typographyStyles = getTypographyStyles(typography);
62
+ const focusStyles = {
63
+ boxShadow: inverted ? theme.boxShadow.INVERTED : theme.boxShadow.NORMAL,
64
+ };
62
65
  return (_jsxs("div", Object.assign({ ref: ref, onClick: onClick, id: id, sx: Object.assign(Object.assign({ height,
63
- display, px: paddingX, border: 'solid 1px', borderColor: COLOR.GRAY, borderRadius: '4px', flexDirection: 'row', position: 'relative', alignItems: 'center', ':hover': {
64
- boxShadow: theme.boxShadow.NORMAL,
65
- }, ':focus': {
66
- boxShadow: theme.boxShadow.NORMAL,
67
- } }, typographyStyles), sx) }, { children: [leftIcon && (_jsx(Icon, { icon: leftIcon, sx: {
66
+ display, px: paddingX, backgroundColor: inverted ? COLOR.DARK_GRAY : COLOR.WHITE, borderRadius: '4px', flexDirection: 'row', position: 'relative', alignItems: 'center', ':hover': focusStyles, ':focus': focusStyles }, typographyStyles), sx) }, { children: [_jsx("fieldset", Object.assign({ sx: {
67
+ textAlign: 'left',
68
+ position: 'absolute',
69
+ inset: '-5px 0px 0px 0px',
70
+ margin: '0px',
71
+ padding: '0px 0.5rem',
72
+ pointerEvents: 'none',
73
+ borderRadius: 'inherit',
74
+ borderStyle: 'solid',
75
+ borderWidth: '1px',
76
+ overflow: 'hidden',
77
+ minWidth: '0%',
78
+ borderColor: inverted ? COLOR.GRAY : COLOR.LIGHT_GRAY,
79
+ zIndex: theme.zIndex.LABEL,
80
+ }, "aria-ignore": true }, { children: _jsx("legend", Object.assign({ style: {
81
+ width: 'auto',
82
+ float: 'unset',
83
+ overflow: 'hidden',
84
+ position: 'relative',
85
+ display: 'block',
86
+ padding: '0',
87
+ height: '8px',
88
+ fontSize: '0.75em',
89
+ visibility: 'hidden',
90
+ whiteSpace: 'nowrap',
91
+ } }, { children: label && (_jsx(Label, Object.assign({ standalone: true, "aria-hidden": "true", sx: {
92
+ px: 1,
93
+ position: 'relative',
94
+ display: 'inline-flex',
95
+ opacity: '0',
96
+ visibility: 'hidden',
97
+ }, typography: labelTypographyMap[size] }, { children: label }))) })) })), leftIcon && (_jsx(Icon, { icon: leftIcon, color: inverted ? COLOR.EXTRA_LIGHT_GRAY : COLOR.TEXT, sx: {
68
98
  mr: 2,
69
99
  fontSize: getIconSize(typographyStyles.fontSize),
70
100
  } })), _jsx("input", Object.assign({ value: value, onChange: (event) => {
71
101
  onChange && onChange(event.target.value);
72
102
  onChangeRaw && onChangeRaw(event);
73
- }, sx: Object.assign(Object.assign({ px: 0, py: 0, width: '100%', border: 'none' }, typographyStyles), { ':focus': {
103
+ }, sx: Object.assign(Object.assign({ px: 0, py: 0, width: '100%', border: 'none', backgroundColor: inverted ? COLOR.DARK_GRAY : COLOR.WHITE, color: inverted ? COLOR.EXTRA_LIGHT_GRAY : COLOR.TEXT }, typographyStyles), { '::placeholder': {
104
+ color: inverted ? COLOR.LIGHT_GRAY : COLOR.GRAY,
105
+ }, ':focus': {
74
106
  outline: 'none',
75
107
  } }) }, rest)), label && (_jsx(Label, Object.assign({ htmlFor: id, typography: labelTypographyMap[size], sx: {
76
108
  position: 'absolute',
77
- color: COLOR.ND_PROVOST_BLUE,
78
- backgroundColor: COLOR.WHITE,
109
+ color: inverted ? COLOR.EXTRA_LIGHT_GRAY : COLOR.ND_PROVOST_BLUE,
79
110
  left: '0.5rem',
80
111
  lineHeight: 1,
81
112
  zIndex: theme.zIndex.LABEL,
82
- px: size === INPUT_SIZE.SM ? 1 : 2,
113
+ px: 1,
83
114
  top: labelOffsetMap[size],
84
115
  } }, { children: label })))] })));
85
116
  });
@@ -1,6 +1,7 @@
1
1
  export declare enum BOX_SHADOW {
2
2
  NORMAL = "0 0 8px #dfdfdf",
3
- EMPHASIZED = "0 0 12px #d3d3d3"
3
+ EMPHASIZED = "0 0 12px #d3d3d3",
4
+ INVERTED = "0 0 8px #767676"
4
5
  }
5
6
  export declare enum Z_INDEX {
6
7
  NORMAL = 1,
@@ -3,6 +3,7 @@ export var BOX_SHADOW;
3
3
  (function (BOX_SHADOW) {
4
4
  BOX_SHADOW["NORMAL"] = "0 0 8px #dfdfdf";
5
5
  BOX_SHADOW["EMPHASIZED"] = "0 0 12px #d3d3d3";
6
+ BOX_SHADOW["INVERTED"] = "0 0 8px #767676";
6
7
  })(BOX_SHADOW || (BOX_SHADOW = {}));
7
8
  export var Z_INDEX;
8
9
  (function (Z_INDEX) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndlib/component-library",
3
- "version": "0.0.37",
3
+ "version": "0.0.38",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [