@vev/silke 1.0.6 → 1.0.7

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.
@@ -6,17 +6,20 @@ import postcss from 'postcss';
6
6
 
7
7
  export function esbuildSassModulesPlugin() {
8
8
  const globalVar = global;
9
- globalVar.allCSS = '';
10
9
 
11
10
  return {
12
11
  name: 'sass-modules-plugin',
13
12
  setup(build) {
13
+ globalVar.allCSS = {};
14
+
14
15
  build.onLoad({ filter: /\.(s[ac]ss|css)$/ }, async (args) => {
15
16
  const content = await sass.compileAsync(args.path);
16
17
  let classNameMap = {};
17
18
 
18
19
  const { css } = await postcss([
19
20
  postCSSmodules({
21
+ scopeBehaviour: 'local',
22
+ generateScopedName: 'silke-[local]__[hash:base64:5]',
20
23
  getJSON(cssFileName, json) {
21
24
  classNameMap = json;
22
25
  },
@@ -24,7 +27,7 @@ export function esbuildSassModulesPlugin() {
24
27
  autoprefixer(),
25
28
  ]).process(content.css);
26
29
 
27
- globalVar.allCSS += css;
30
+ globalVar.allCSS[args.path] = css;
28
31
 
29
32
  return {
30
33
  contents: `export default ${JSON.stringify(classNameMap)};`,
@@ -33,7 +36,8 @@ export function esbuildSassModulesPlugin() {
33
36
  });
34
37
 
35
38
  build.onEnd(async () => {
36
- await fsAsync.writeFile(`${build.initialOptions.outdir}/styles.css`, globalVar.allCSS);
39
+ const css = Object.values(globalVar.allCSS).join('\n');
40
+ await fsAsync.writeFile(`${build.initialOptions.outdir}/styles.css`, css);
37
41
  });
38
42
  },
39
43
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vev/silke",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -94,6 +94,7 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
94
94
  renderTags: TagsRender = AutocompleteTags,
95
95
  sort = sorter,
96
96
  label,
97
+ inlineLabelWidth,
97
98
  inline,
98
99
  flex,
99
100
  anchorOrigin,
@@ -309,6 +310,7 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
309
310
  ref={containerRef}
310
311
  name={form.name}
311
312
  inline={inline}
313
+ inlineLabelWidth={inlineLabelWidth}
312
314
  size={size}
313
315
  flex={flex}
314
316
  label={label}
@@ -0,0 +1,76 @@
1
+ import React, { RefObject, useCallback, useRef } from 'react';
2
+ import { SilkeSchemaFields } from '../silke-schema-fields';
3
+ import { SilkeTextField } from '../../silke-text-field';
4
+ import { FieldRegisterModel, FormObjectProvider } from '../../silke-form/form-context';
5
+ import { SilkeText } from '../../silke-text';
6
+ import { SilkeBox } from '../../silke-box';
7
+ import { SilkeButton } from '../../silke-button';
8
+ import { generateTitle } from './utils';
9
+ import { VevProps } from '@vev/react';
10
+ import styles from './styles.scss';
11
+
12
+ type Props = {
13
+ selected: number;
14
+ value: any[];
15
+ schema: VevProps | string;
16
+ onChange: (value: any[]) => void;
17
+ onDelete: () => void;
18
+ onClose: () => void;
19
+ };
20
+
21
+ export function ArrayFieldInline({ value, selected, schema, onChange, onDelete, onClose }: Props) {
22
+ const valueRef = useRef<any>(value);
23
+ const fieldRefs = useRef<any>({});
24
+
25
+ const registerField = useCallback((name: any, v: FieldRegisterModel) => {
26
+ fieldRefs.current[name] = v;
27
+ }, []);
28
+
29
+ return (
30
+ <SilkeBox column bg="layer">
31
+ <SilkeBox pad="s" vAlign="center">
32
+ <SilkeBox hPad="s" vPad="s" flex>
33
+ <SilkeText weight="strong">
34
+ {generateTitle(value[selected], schema) || 'Untitled'}
35
+ </SilkeText>
36
+ </SilkeBox>
37
+ <SilkeButton icon="delete" kind="ghost" size="m" onClick={onDelete} />
38
+ <SilkeButton icon="close" kind="ghost" size="m" onClick={onClose} />
39
+ </SilkeBox>
40
+ <SilkeBox hPad="m" gap="m" column vAlign="center">
41
+ {typeof schema === 'string' ? (
42
+ <SilkeTextField
43
+ value={(selected !== undefined && value[selected]) || ''}
44
+ type={(schema as any).of}
45
+ onChange={(val: string) => {
46
+ const update = value || [];
47
+ update[selected] = val;
48
+ onChange(update);
49
+ }}
50
+ />
51
+ ) : (
52
+ <FormObjectProvider
53
+ errors={{}}
54
+ valueRef={valueRef}
55
+ value={value[selected] || {}}
56
+ validate={() => {}}
57
+ onChange={(name, update) => {
58
+ value[selected] = {
59
+ ...value[selected],
60
+ [name]: update,
61
+ };
62
+ onChange(value);
63
+ }}
64
+ register={registerField}
65
+ >
66
+ <SilkeSchemaFields
67
+ schema={[schema]}
68
+ value={(selected && value[selected]) || {}}
69
+ noPad
70
+ />
71
+ </FormObjectProvider>
72
+ )}
73
+ </SilkeBox>
74
+ </SilkeBox>
75
+ );
76
+ }
@@ -94,11 +94,3 @@ export function ArrayFieldModal({
94
94
  </SilkePopover>
95
95
  );
96
96
  }
97
-
98
- const OriginMap: Record<string, number> = {
99
- top: 0,
100
- bottom: 1,
101
- left: 0,
102
- right: 1,
103
- center: 0.5,
104
- };
@@ -8,6 +8,7 @@ import { SilkeSortableList } from '../../silke-sortable-list';
8
8
  import { SilkeText, SilkeTextSmall } from '../../silke-text';
9
9
  import styles from './styles.scss';
10
10
  import { ArrayFieldModal } from './array-field-modal';
11
+ import { ArrayFieldInline } from './array-field-inline';
11
12
  import { getTitle } from './string-field';
12
13
  import { SilkeOverflowMenu } from '../../silke-overflow-menu';
13
14
  import { generateTitle, generateImage } from './utils';
@@ -16,6 +17,7 @@ import { isString, startCase } from 'lodash';
16
17
  const ArrayField = ({ value = [], schema, onChange }: SchemaFieldProps<ArrayFieldType>) => {
17
18
  const [selected, setSelected] = useState<number | undefined>(undefined);
18
19
  const [schemaIndex, setSchemaIndex] = useState(0);
20
+ const isModal = true;
19
21
 
20
22
  const listRefs = useRef<any[]>([]);
21
23
  const headerRef = useRef<any>(null);
@@ -39,13 +41,26 @@ const ArrayField = ({ value = [], schema, onChange }: SchemaFieldProps<ArrayFiel
39
41
  <SilkeOverflowMenu
40
42
  size="base"
41
43
  icon="add"
42
- items={(schema.of as VevProps[]).map((item, i) => ({
43
- label: item.title || startCase(item.name),
44
- onClick: () => {
45
- setSchemaIndex(i);
46
- setSelected(value.length || 0);
47
- },
48
- }))}
44
+ items={(schema.of as VevProps[]).map((item, i) => {
45
+ const icon = generateImage([], item);
46
+ const Icon = () =>
47
+ icon ? (
48
+ isString(icon) ? (
49
+ <img className={styles.icon} src={icon} />
50
+ ) : (
51
+ <span className={styles.icon}>{icon}</span>
52
+ )
53
+ ) : null;
54
+
55
+ return {
56
+ label: item.title || startCase(item.name),
57
+ icon: <Icon />,
58
+ onClick: () => {
59
+ setSchemaIndex(i);
60
+ setSelected(value.length || 0);
61
+ },
62
+ };
63
+ })}
49
64
  />
50
65
  ) : (
51
66
  <SilkeButton
@@ -60,17 +75,29 @@ const ArrayField = ({ value = [], schema, onChange }: SchemaFieldProps<ArrayFiel
60
75
  </SilkeBox>
61
76
  </SilkeBox>
62
77
  {schema.description && <SilkeText color="secondary">{schema.description}</SilkeText>}
63
- {selected !== undefined && (
64
- <ArrayFieldModal
65
- anchor={listRefs.current[selected] ? { current: listRefs.current[selected] } : headerRef}
66
- value={value}
67
- selected={selected}
68
- onChange={onChange}
69
- onDelete={handleDeleteItem}
70
- schema={Array.isArray(schema.of) ? schema.of[schemaIndex] : schema.of}
71
- onClose={() => setSelected(undefined)}
72
- />
73
- )}
78
+ {selected !== undefined &&
79
+ (isModal ? (
80
+ <ArrayFieldModal
81
+ anchor={
82
+ listRefs.current[selected] ? { current: listRefs.current[selected] } : headerRef
83
+ }
84
+ value={value}
85
+ selected={selected}
86
+ onChange={onChange}
87
+ onDelete={handleDeleteItem}
88
+ schema={Array.isArray(schema.of) ? schema.of[schemaIndex] : schema.of}
89
+ onClose={() => setSelected(undefined)}
90
+ />
91
+ ) : (
92
+ <ArrayFieldInline
93
+ value={value}
94
+ selected={selected}
95
+ onChange={onChange}
96
+ onDelete={handleDeleteItem}
97
+ schema={Array.isArray(schema.of) ? schema.of[schemaIndex] : schema.of}
98
+ onClose={() => setSelected(undefined)}
99
+ />
100
+ ))}
74
101
  {!value.length && (
75
102
  <>
76
103
  <SilkeBox>
@@ -85,7 +112,6 @@ const ArrayField = ({ value = [], schema, onChange }: SchemaFieldProps<ArrayFiel
85
112
  const fieldSchema = Array.isArray(schema.of)
86
113
  ? schema.of.find((s: VevProps) => s.name === schemaType)
87
114
  : schema.of;
88
-
89
115
  const imageUrl = generateImage(item, fieldSchema);
90
116
 
91
117
  return (
@@ -94,7 +120,7 @@ const ArrayField = ({ value = [], schema, onChange }: SchemaFieldProps<ArrayFiel
94
120
  column
95
121
  ref={(el: HTMLDivElement) => (listRefs.current[i] = el)}
96
122
  className={styles.arrayItem}
97
- hPad={'m'}
123
+ vPad="xs"
98
124
  >
99
125
  <SilkeBox vAlign="center" vPad="xxs">
100
126
  <SilkeBox
@@ -82,6 +82,8 @@ const SelectField = (props: SchemaFieldProps<LinkFieldType>) => {
82
82
  onChange={(val: string) => handleAddPageLink(val)}
83
83
  onAdd={(val: string) => handleAddLink(val)}
84
84
  size="xs"
85
+ inline
86
+ inlineLabelWidth={80}
85
87
  />
86
88
  <SilkeBox>
87
89
  <SilkeTextSmall flex>Open in new tab</SilkeTextSmall>
@@ -76,6 +76,8 @@ const NumberField = (props: SchemaFieldProps<NumberFieldType>) => {
76
76
  onChange={(value: number) => onChange(value / scale)}
77
77
  size="xs"
78
78
  label={getTitle(schema)}
79
+ inline
80
+ inlineLabelWidth={80}
79
81
  flex
80
82
  />
81
83
  );
@@ -12,7 +12,7 @@ export default function ObjectField({
12
12
  onChange,
13
13
  }: SchemaFieldProps<ObjectFieldType>) {
14
14
  return (
15
- <SilkeBox column flex gap="m" style={{ paddingBottom: '16px' }}>
15
+ <SilkeBox column flex style={{ paddingBottom: '16px' }}>
16
16
  <SilkeTextSmall weight="strong">{getTitle(schema)}</SilkeTextSmall>
17
17
  {schema.description && (
18
18
  <SilkeTextSmall color="secondary">{schema.description}</SilkeTextSmall>
@@ -1,10 +1,11 @@
1
1
  import { SchemaFieldProps, SelectField as SelectFieldType, SelectFieldItem } from '@vev/react';
2
2
  import { isArray, isFunction, startCase } from 'lodash';
3
3
  import React, { useEffect, useState } from 'react';
4
+ import { SilkeTextSmall } from 'src/components/silke-text/silke-text';
4
5
  import { SilkeAutocompleteField } from '../../silke-autocomplete-field';
5
6
  import { SilkeBox } from '../../silke-box';
6
7
  import { SilkeCheckbox } from '../../silke-checkbox';
7
- import { SilkeRadioButtonGroup } from '../../silke-radio-button';
8
+ import { SilkeRadioButton, SilkeRadioButtonGroup } from '../../silke-radio-button';
8
9
  import { SilkeSelectField } from '../../silke-select-field';
9
10
  import { useSchemaContext } from '../silke-schema-context';
10
11
  import { getTitle } from './string-field';
@@ -64,6 +65,8 @@ const SelectField = (props: SchemaFieldProps<SelectFieldType>) => {
64
65
  items={items}
65
66
  onChange={onChange}
66
67
  size="xs"
68
+ inline
69
+ inlineLabelWidth={80}
67
70
  />
68
71
  );
69
72
  }
@@ -77,17 +80,22 @@ const SelectField = (props: SchemaFieldProps<SelectFieldType>) => {
77
80
  items={items}
78
81
  onChange={onChange}
79
82
  size="xs"
83
+ inline
84
+ inlineLabelWidth={80}
80
85
  />
81
86
  );
82
87
  }
83
88
  return (
84
- <SilkeRadioButtonGroup
85
- {...props}
86
- name={name}
87
- label={getTitle(schema)}
88
- items={items}
89
- size="small"
90
- />
89
+ <SilkeBox gap="xs">
90
+ <SilkeTextSmall color="secondary" style={{ width: '80px' }}>
91
+ {getTitle(schema)}
92
+ </SilkeTextSmall>
93
+ <SilkeBox column>
94
+ {items?.map((item, i) => (
95
+ <SilkeRadioButton key={i} {...item} name={name} size="small" />
96
+ ))}
97
+ </SilkeBox>
98
+ </SilkeBox>
91
99
  );
92
100
  };
93
101
 
@@ -12,6 +12,8 @@ const StringField = ({ schema, ...rest }: SchemaFieldProps<StringFieldType>) =>
12
12
  return (
13
13
  <SilkeTextField
14
14
  {...rest}
15
+ inline
16
+ inlineLabelWidth={80}
15
17
  type={options?.type || 'text'}
16
18
  minLength={options?.minLength}
17
19
  maxLength={options?.maxLength}
@@ -12,6 +12,11 @@
12
12
  align-items: center;
13
13
  }
14
14
 
15
+ .icon {
16
+ width: 24px;
17
+ height: 24px;
18
+ }
19
+
15
20
  .arrayItem {
16
21
  padding: 4px 0;
17
22
  border-radius: 4px;
@@ -6,15 +6,15 @@ import { SilkeTextSmall } from '../../silke-text';
6
6
 
7
7
  const Toggle = (props: SchemaFieldProps<BooleanField>) => (
8
8
  <SilkeBox flex>
9
- <SilkeBox align="start" flex column>
9
+ <SilkeBox align="start" style={{ width: '80px' }}>
10
10
  <SilkeBox vAlign="center" flex>
11
- <SilkeTextSmall>{props.schema.title || props.schema.name}</SilkeTextSmall>
11
+ <SilkeTextSmall color="secondary">{props.schema.title || props.schema.name}</SilkeTextSmall>
12
12
  </SilkeBox>
13
13
  {props.schema.description && (
14
14
  <SilkeTextSmall color="secondary">{props.schema.description}</SilkeTextSmall>
15
15
  )}
16
16
  </SilkeBox>
17
- <SilkeBox align="end" pad="xs">
17
+ <SilkeBox flex pad="xs">
18
18
  <SilkeToggle value={props.value || false} onChange={props.onChange} small />
19
19
  </SilkeBox>
20
20
  </SilkeBox>
@@ -12,24 +12,22 @@ type SilkeSchemaFieldsProps<T> = {
12
12
  } & SilkeFormProps<T>;
13
13
 
14
14
  export function SilkeSchemaFields<T>(props: SilkeSchemaFieldsProps<T>) {
15
- const { schema, row, ...rest } = props;
16
-
15
+ const { schema = [], row, ...rest } = props;
17
16
  return (
18
17
  <SilkeBox flex column={!row} gap="m" style={{ width: '100%' }}>
18
+ {schema[0]?.type !== 'array' && <div />}
19
19
  {schema.map((field, index) => {
20
20
  const comp = SilkeSchemaField({ field, ...rest });
21
- return (
22
- comp && (
23
- <span style={{ overflow: 'hidden' }} key={(field.name || 'field') + index}>
24
- {comp}
25
- {['object', 'array', 'image'].includes(field.type) && index < schema.length - 1 && (
26
- <SilkeBox column flex key={index}>
27
- <SilkeDivider dark />
28
- </SilkeBox>
29
- )}
30
- </span>
31
- )
32
- );
21
+ return comp ? (
22
+ <span style={{ overflow: 'hidden' }} key={(field.name || 'field') + index}>
23
+ {comp}
24
+ {['object', 'array', 'image'].includes(field.type) && index < schema.length - 1 && (
25
+ <SilkeBox column flex key={index}>
26
+ <SilkeDivider dark />
27
+ </SilkeBox>
28
+ )}
29
+ </span>
30
+ ) : null;
33
31
  })}
34
32
  </SilkeBox>
35
33
  );
@@ -37,18 +37,6 @@ $circleBorderWidth: 1px;
37
37
  input:checked ~ .circle {
38
38
  color: var(--color-brand-secondary-bright);
39
39
  }
40
-
41
- input:focus ~ .circle:before {
42
- position: absolute;
43
- top: -5px;
44
- left: -5px;
45
- right: -5px;
46
- bottom: -5px;
47
- content: "";
48
- border: 2px solid var(--color-neutral-high-pure);
49
- display: block;
50
- border-radius: 50%;
51
- }
52
40
  }
53
41
  }
54
42
 
@@ -37,6 +37,8 @@ export type SilkeTextFieldOutlineProps = {
37
37
  hAlign?: BoxProps['hAlign'];
38
38
  /** Inline will add the label before the input field */
39
39
  inline?: boolean;
40
+ /** Width of the inline label */
41
+ inlineLabelWidth?: number;
40
42
  /** Field required input (if string the string will be used as error msg) */
41
43
  /** Helpful tip or explanation of function of the field */
42
44
  help?: React.ReactNode;
@@ -74,6 +76,7 @@ export const SilkeTextFieldOutline = React.forwardRef<HTMLDivElement, SilkeTextF
74
76
  onClick,
75
77
  onMouseDown,
76
78
  disabled,
79
+ inlineLabelWidth,
77
80
  }: SilkeTextFieldOutlineProps,
78
81
  ref,
79
82
  ) => {
@@ -106,7 +109,13 @@ export const SilkeTextFieldOutline = React.forwardRef<HTMLDivElement, SilkeTextF
106
109
  onMouseDown={onMouseDown}
107
110
  >
108
111
  {label && (
109
- <SilkeText className={styles.label} tag="label" htmlFor={labelId} color="secondary">
112
+ <SilkeText
113
+ className={styles.label}
114
+ tag="label"
115
+ htmlFor={labelId}
116
+ color="secondary"
117
+ style={inlineLabelWidth ? { width: `${inlineLabelWidth}px` } : undefined}
118
+ >
110
119
  {label}
111
120
  </SilkeText>
112
121
  )}
@@ -77,6 +77,7 @@ export const SilkeTextField = React.forwardRef<HTMLDivElement, SilkeTextFieldPro
77
77
  kind,
78
78
  inline,
79
79
  disabled,
80
+ inlineLabelWidth,
80
81
  ...rest
81
82
  } = useFormField(props, validateText);
82
83
 
@@ -126,6 +127,7 @@ export const SilkeTextField = React.forwardRef<HTMLDivElement, SilkeTextFieldPro
126
127
  className={className}
127
128
  error={error}
128
129
  inline={inline}
130
+ inlineLabelWidth={inlineLabelWidth}
129
131
  helpId={helpId}
130
132
  labelId={inputId}
131
133
  help={help}