techsbcn-storybook 2.11.2 → 2.13.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.
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { SearchFilters } from '../../../interfaces';
2
+ import { SearchFilters, SelectOptionTag } from '../../../interfaces';
3
3
 
4
4
  type MenuPlacement = 'bottom' | 'auto' | 'top';
5
5
  interface SelectAsyncFieldProps {
@@ -22,6 +22,7 @@ interface SelectAsyncFieldProps {
22
22
  menuPlacement?: MenuPlacement;
23
23
  value?: any[];
24
24
  getOptionLabel?: (option: any) => any;
25
+ getOptionTag?: (option: any) => SelectOptionTag | undefined;
25
26
  noBorders?: boolean;
26
27
  }
27
28
  export declare const SelectAsyncField: React.FunctionComponent<SelectAsyncFieldProps>;
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { SelectOptionTag } from '../../../interfaces';
2
3
 
3
4
  type MenuPlacement = 'bottom' | 'auto' | 'top';
4
5
  interface SelectFieldProps {
@@ -22,6 +23,7 @@ interface SelectFieldProps {
22
23
  isLoading?: boolean;
23
24
  value?: any[];
24
25
  getOptionLabel?: (option: any) => any;
26
+ getOptionTag?: (option: any) => SelectOptionTag | undefined;
25
27
  addExtraOption?: any;
26
28
  noBorders?: boolean;
27
29
  }
@@ -0,0 +1,4 @@
1
+ import { SelectOptionTag } from '../../../interfaces';
2
+ export declare const buildFormatOptionLabel: (getOptionTag?: (option: any) => SelectOptionTag | undefined, getOptionLabel?: (option: any) => any) => (option: any, meta: {
3
+ context: "menu" | "value";
4
+ }) => any;
@@ -10,6 +10,7 @@ export interface SearchComponentProps {
10
10
  extraActions?: {
11
11
  action: any;
12
12
  }[];
13
+ inlineExtraActions?: boolean;
13
14
  filters?: {
14
15
  singleFilter?: any;
15
16
  doubleFilter?: DoubleFilter;
package/dist/index.js CHANGED
@@ -139,15 +139,17 @@ var SearchComponent = (props) => {
139
139
  setAnchorEl(null);
140
140
  };
141
141
  const randId = Math.random().toString(36).substring(7);
142
+ const inlineExtraActions = !!props.extraActions && !!props.inlineExtraActions;
143
+ const extraActions = props.extraActions && /* @__PURE__ */ React10__default.default.createElement(material.Box, { className: "extra-actions", sx: { display: "flex", flexWrap: "wrap", gap: 1, mt: inlineExtraActions ? 0 : 2 } }, props.extraActions.map((action, i) => /* @__PURE__ */ React10__default.default.createElement(React10__default.default.Fragment, { key: i }, action.action)));
142
144
  return /* @__PURE__ */ React10__default.default.createElement(material.Box, { className: `search-component ${props.className}` }, /* @__PURE__ */ React10__default.default.createElement(material.Box, { sx: { mb: props.divider ? 2 : 0, px: 2 } }, /* @__PURE__ */ React10__default.default.createElement(material.Grid, { container: true, sx: { alignItems: "center" } }, /* @__PURE__ */ React10__default.default.createElement(
143
145
  material.Grid,
144
146
  {
145
147
  size: {
146
148
  xs: props.actions ? 8 : 12,
147
- md: props.actions && props.searchBar ? 4 : props.searchBar ? 7 : props.actions ? 6 : 12
149
+ md: inlineExtraActions ? "grow" : props.actions && props.searchBar ? 4 : props.searchBar ? 7 : props.actions ? 6 : 12
148
150
  }
149
151
  },
150
- /* @__PURE__ */ React10__default.default.createElement(
152
+ /* @__PURE__ */ React10__default.default.createElement(material.Box, { sx: { display: "flex", alignItems: "center", flexWrap: "wrap", gap: 2 } }, /* @__PURE__ */ React10__default.default.createElement(
151
153
  material.Box,
152
154
  {
153
155
  sx: {
@@ -158,7 +160,7 @@ var SearchComponent = (props) => {
158
160
  className: `${props.enableAfter ? "main-background-color-after" : ""} title`
159
161
  },
160
162
  props.title
161
- )
163
+ ), inlineExtraActions && extraActions)
162
164
  ), props.actions && /* @__PURE__ */ React10__default.default.createElement(material.Grid, { size: { xs: props.title ? 4 : 12 }, sx: { display: { xs: "block", md: "none" } } }, /* @__PURE__ */ React10__default.default.createElement(material.Box, { sx: { display: { xs: "none", md: "flex" } } }, ActionsList(props.actions)), /* @__PURE__ */ React10__default.default.createElement(material.Box, { sx: { display: { xs: "flex", md: "none" } } }, props.actions.length > 1 ? /* @__PURE__ */ React10__default.default.createElement(material.Box, { sx: { ml: "auto" } }, /* @__PURE__ */ React10__default.default.createElement(
163
165
  material.IconButton,
164
166
  {
@@ -185,27 +187,36 @@ var SearchComponent = (props) => {
185
187
  className: "search-menu-actions"
186
188
  },
187
189
  props.actions.map((action, i) => /* @__PURE__ */ React10__default.default.createElement(material.MenuItem, { key: i, className: "wrapper-actions" }, /* @__PURE__ */ React10__default.default.createElement(material.Box, { className: "btn-action main-color", sx: { color: "primary.main" } }, action.action)))
188
- )) : /* @__PURE__ */ React10__default.default.createElement(material.Box, { sx: { ml: "auto" }, className: `wrapper-actions ${props.title ? "min-action-width" : ""}` }, ActionsList(props.actions)))), (props.searchBar || props.filters || props.actions) && /* @__PURE__ */ React10__default.default.createElement(material.Grid, { size: { xs: 12, md: props.actions && props.searchBar ? 8 : props.actions ? 6 : 5 } }, /* @__PURE__ */ React10__default.default.createElement(material.Box, { sx: { display: "flex", alignItems: "center" } }, /* @__PURE__ */ React10__default.default.createElement(
189
- material.Box,
190
+ )) : /* @__PURE__ */ React10__default.default.createElement(material.Box, { sx: { ml: "auto" }, className: `wrapper-actions ${props.title ? "min-action-width" : ""}` }, ActionsList(props.actions)))), (props.searchBar || props.filters || props.actions) && /* @__PURE__ */ React10__default.default.createElement(
191
+ material.Grid,
190
192
  {
191
- sx: {
192
- ml: "auto",
193
- display: "flex",
194
- width: "100%",
195
- ...(props.searchBar || props.filters) && { mt: { xs: 2, md: 0 } }
193
+ size: {
194
+ xs: 12,
195
+ md: inlineExtraActions ? "auto" : props.actions && props.searchBar ? 8 : props.actions ? 6 : 5
196
196
  }
197
197
  },
198
- props.searchBar,
199
- !!props.fixedOpen || props.filters && props.searchBar && /* @__PURE__ */ React10__default.default.createElement(
198
+ /* @__PURE__ */ React10__default.default.createElement(material.Box, { sx: { display: "flex", alignItems: "center" } }, /* @__PURE__ */ React10__default.default.createElement(
200
199
  material.Box,
201
200
  {
202
- onClick: () => setIsOpen(!isOpen),
203
- className: "tune-btn main-background-color",
204
- sx: { bgcolor: "primary.main", color: "primary.contrastText", "&:hover": { boxShadow: 4 } }
201
+ sx: {
202
+ ml: "auto",
203
+ display: "flex",
204
+ width: "100%",
205
+ ...(props.searchBar || props.filters) && { mt: { xs: 2, md: 0 } }
206
+ }
205
207
  },
206
- /* @__PURE__ */ React10__default.default.createElement(material.Badge, { badgeContent: props.activeFiltersCount, color: "error" }, /* @__PURE__ */ React10__default.default.createElement(iconsMaterial.Tune, null))
207
- )
208
- ), props.actions && /* @__PURE__ */ React10__default.default.createElement(material.Box, { sx: { display: { xs: "none", md: "block" } }, className: "wrapper-actions" }, ActionsList(props.actions))))), props.extraActions && /* @__PURE__ */ React10__default.default.createElement(material.Box, { className: "extra-actions", sx: { display: "flex", flexWrap: "wrap", gap: 1, mt: 2 } }, props.extraActions.map((action, i) => /* @__PURE__ */ React10__default.default.createElement(React10__default.default.Fragment, { key: i }, action.action)))), props.divider && /* @__PURE__ */ React10__default.default.createElement(material.Divider, null), /* @__PURE__ */ React10__default.default.createElement(material.Collapse, { in: isOpen }, /* @__PURE__ */ React10__default.default.createElement(material.Box, { className: "filters", sx: { px: 2, mt: 2, mb: props.divider ? 0 : 1 } }, /* @__PURE__ */ React10__default.default.createElement(material.Grid, { container: true, spacing: 3, sx: { justifyContent: "end" } }, props.filters && props.filters.length > 0 && props.filters.map((filter, i) => /* @__PURE__ */ React10__default.default.createElement(material.Grid, { key: i, size: { xs: 12, sm: props.filtersSize ?? 6, xl: props.filtersSize ?? 4 } }, filter.doubleFilter ? DoubleFilter(filter.doubleFilter) : filter.singleFilter))))));
208
+ props.searchBar,
209
+ !!props.fixedOpen || props.filters && props.searchBar && /* @__PURE__ */ React10__default.default.createElement(
210
+ material.Box,
211
+ {
212
+ onClick: () => setIsOpen(!isOpen),
213
+ className: "tune-btn main-background-color",
214
+ sx: { bgcolor: "primary.main", color: "primary.contrastText", "&:hover": { boxShadow: 4 } }
215
+ },
216
+ /* @__PURE__ */ React10__default.default.createElement(material.Badge, { badgeContent: props.activeFiltersCount, color: "error" }, /* @__PURE__ */ React10__default.default.createElement(iconsMaterial.Tune, null))
217
+ )
218
+ ), props.actions && /* @__PURE__ */ React10__default.default.createElement(material.Box, { sx: { display: { xs: "none", md: "block" } }, className: "wrapper-actions" }, ActionsList(props.actions)))
219
+ )), !inlineExtraActions && extraActions), props.divider && /* @__PURE__ */ React10__default.default.createElement(material.Divider, null), /* @__PURE__ */ React10__default.default.createElement(material.Collapse, { in: isOpen }, /* @__PURE__ */ React10__default.default.createElement(material.Box, { className: "filters", sx: { px: 2, mt: 2, mb: props.divider ? 0 : 1 } }, /* @__PURE__ */ React10__default.default.createElement(material.Grid, { container: true, spacing: 3, sx: { justifyContent: "end" } }, props.filters && props.filters.length > 0 && props.filters.map((filter, i) => /* @__PURE__ */ React10__default.default.createElement(material.Grid, { key: i, size: { xs: 12, sm: props.filtersSize ?? 6, xl: props.filtersSize ?? 4 } }, filter.doubleFilter ? DoubleFilter(filter.doubleFilter) : filter.singleFilter))))));
209
220
  };
210
221
 
211
222
  // src/components/wrappers/LinearProgressComponent/LinearProgressComponent.scss
@@ -2147,6 +2158,27 @@ var selectFieldSx = (theme) => ({
2147
2158
  }
2148
2159
  }
2149
2160
  });
2161
+ var buildFormatOptionLabel = (getOptionTag, getOptionLabel) => (option, meta) => {
2162
+ const optionLabel = getOptionLabel ? getOptionLabel(option) : option.label;
2163
+ const tag = getOptionTag && meta.context === "menu" ? getOptionTag(option) : void 0;
2164
+ if (!tag) return optionLabel;
2165
+ const color = tag.color ?? "primary";
2166
+ return /* @__PURE__ */ React10__default.default.createElement(material.Box, { className: "select-option-with-tag", sx: { display: "flex", alignItems: "center", gap: 1 } }, /* @__PURE__ */ React10__default.default.createElement(material.Box, { sx: { flex: 1, overflow: "hidden", textOverflow: "ellipsis" } }, optionLabel), /* @__PURE__ */ React10__default.default.createElement(
2167
+ material.Chip,
2168
+ {
2169
+ className: "select-option-tag",
2170
+ label: tag.label,
2171
+ size: "small",
2172
+ sx: (theme) => ({
2173
+ height: 20,
2174
+ borderRadius: 1,
2175
+ fontWeight: 600,
2176
+ color: `${theme.palette[color].main} !important`,
2177
+ backgroundColor: styles.alpha(theme.palette[color].main, 0.12)
2178
+ })
2179
+ }
2180
+ ));
2181
+ };
2150
2182
 
2151
2183
  // src/components/fields/SelectFieldComponent/SelectField.scss
2152
2184
  var css16 = `.select-field .MuiFormLabel-root {
@@ -2218,6 +2250,7 @@ var SelectField = ({
2218
2250
  menuPlacement: props.menuPlacement,
2219
2251
  value: props.value,
2220
2252
  getOptionLabel: props.getOptionLabel,
2253
+ formatOptionLabel: props.getOptionTag ? buildFormatOptionLabel(props.getOptionTag, props.getOptionLabel) : void 0,
2221
2254
  theme: buildReactSelectTheme(theme),
2222
2255
  styles: buildReactSelectStyles(theme)
2223
2256
  }
@@ -2292,6 +2325,7 @@ var SelectAsyncField = ({
2292
2325
  menuPlacement: props.menuPlacement,
2293
2326
  value: props.value,
2294
2327
  getOptionLabel: props.getOptionLabel,
2328
+ formatOptionLabel: props.getOptionTag ? buildFormatOptionLabel(props.getOptionTag, props.getOptionLabel) : void 0,
2295
2329
  theme: buildReactSelectTheme(theme),
2296
2330
  styles: buildReactSelectStyles(theme)
2297
2331
  }