@soul-refiner/design-system 0.2.19 → 0.2.21

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.
@@ -3,7 +3,7 @@ import { TElement } from '@udecode/plate';
3
3
  export interface EditorProps {
4
4
  communityName: string;
5
5
  editable: boolean;
6
- handleUploadImage: (dataURL: File) => Promise<string>;
6
+ handleUploadImage: (files: FileList) => Promise<string>;
7
7
  onChange: (newNodes: TElement[]) => void;
8
8
  }
9
9
  export declare const Editor: ({ editable, handleUploadImage, onChange, }: EditorProps) => React.JSX.Element;
@@ -2,7 +2,11 @@ import React from 'react';
2
2
  import { setAlign } from '@udecode/plate';
3
3
  import { useAlignDropdownMenu, useAlignDropdownMenuState, } from '@udecode/plate-alignment';
4
4
  import { Dropdown } from '../../';
5
- import { PlayerListPlay, AlignCenter, AlignJustified, AlignLeft, AlignRight, } from '../../../icons';
5
+ import { AlignCenter } from '../../../icons/text/align_center';
6
+ import { AlignJustified } from '../../../icons/text/align_justified';
7
+ import { AlignLeft } from '../../../icons/text/align_left';
8
+ import { AlignRight } from '../../../icons/text/align_right';
9
+ import { PlayerListPlay } from '../../../icons';
6
10
  import { MenuButton } from './navbar';
7
11
  const items = [
8
12
  {
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  export interface EditorBarProps {
3
- handleUploadImage: (dataURL: File) => Promise<string>;
3
+ handleUploadImage: (files: FileList) => Promise<string>;
4
4
  }
5
5
  export declare const EditorBar: ({ handleUploadImage }: EditorBarProps) => React.JSX.Element;
6
6
  export declare const MenuButton: import("styled-components").IStyledComponent<"web", "button", {
@@ -59,11 +59,11 @@ export const EditorBar = ({ handleUploadImage }) => {
59
59
  },
60
60
  ]);
61
61
  };
62
- const handleImageChange = async (event) => {
63
- const file = event.target?.files?.[0];
64
- if (!file)
62
+ const handleImageChange = async () => {
63
+ const files = imageRef.current?.files;
64
+ if (!files)
65
65
  return;
66
- const imageurl = await handleUploadImage(file);
66
+ const imageurl = await handleUploadImage(files);
67
67
  if (imageurl) {
68
68
  insertImage(editorRef, imageurl);
69
69
  }
@@ -71,8 +71,8 @@ export const EditorBar = ({ handleUploadImage }) => {
71
71
  const handleRedo = () => editorRef.redo();
72
72
  const handleUndo = () => editorRef.undo();
73
73
  const handleVideoChange = async (event) => {
74
- const file = event.target?.files?.[0];
75
- if (!file)
74
+ const files = videoRef.current?.files;
75
+ if (!files)
76
76
  return;
77
77
  /**
78
78
  * TODO: Insert video component
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  export interface EditorBarProps {
3
- handleUploadImage: (dataURL: File) => Promise<string>;
3
+ handleUploadImage: (files: FileList) => Promise<string>;
4
4
  }
5
5
  export declare const EditorBar: ({ handleUploadImage }: EditorBarProps) => React.JSX.Element;
6
6
  export declare const MenuButton: import("styled-components").IStyledComponent<"web", "button", {
@@ -1,12 +1,11 @@
1
1
  import React from 'react';
2
2
  import styled from 'styled-components';
3
- import { insertImage, useLinkToolbarButton, useLinkToolbarButtonState, useListToolbarButton, useListToolbarButtonState, useMarkToolbarButton, useMarkToolbarButtonState, usePlateEditorRef, usePlateEditorState, } from '@udecode/plate';
3
+ import { insertImage, useLinkToolbarButton, useLinkToolbarButtonState, useListToolbarButton, useListToolbarButtonState, useMarkToolbarButton, useMarkToolbarButtonState, usePlateEditorRef, } from '@udecode/plate';
4
4
  import { Tooltip } from '../../';
5
5
  import { Bold, Image, Italic, Link, ListOrdered, ListUnordered, Redo, Underline, Undo, } from '../../../icons';
6
6
  import { ELEMENT_OL, ELEMENT_UL, MARK_BOLD, MARK_ITALIC, MARK_UNDERLINE, } from '../constants';
7
7
  export const EditorBar = ({ handleUploadImage }) => {
8
8
  const editorRef = usePlateEditorRef('main');
9
- const stateEditor = usePlateEditorState();
10
9
  const imageRef = React.useRef(null);
11
10
  const boldState = useMarkToolbarButtonState({ nodeType: MARK_BOLD });
12
11
  const { props: { pressed: currBold, onClick: handleBold }, } = useMarkToolbarButton(boldState);
@@ -24,11 +23,11 @@ export const EditorBar = ({ handleUploadImage }) => {
24
23
  nodeType: ELEMENT_UL,
25
24
  });
26
25
  const { props: { pressed: currUnorderedList, onClick: handleUnorderedList }, } = useListToolbarButton(unorderedListState);
27
- const handleImageChange = async (event) => {
28
- const file = event.target?.files?.[0];
29
- if (!file)
26
+ const handleImageChange = async () => {
27
+ const files = imageRef.current?.files;
28
+ if (!files)
30
29
  return;
31
- const imageurl = await handleUploadImage(file);
30
+ const imageurl = await handleUploadImage(files);
32
31
  if (imageurl) {
33
32
  insertImage(editorRef, imageurl);
34
33
  }
@@ -3,7 +3,7 @@ import { TElement } from '@udecode/plate';
3
3
  export interface SimpleEditorProps {
4
4
  communityName: string;
5
5
  editable: boolean;
6
- handleUploadImage: (dataURL: File) => Promise<string>;
6
+ handleUploadImage: (files: FileList) => Promise<string>;
7
7
  onChange: (newNodes: TElement[]) => void;
8
8
  placeholder?: string;
9
9
  }
@@ -56,7 +56,7 @@ export const Chip = ({ children, color, dot, onDismiss, size }) => {
56
56
  return (React.createElement(Component, { "$bgColor": bgColor, "$size": size, "$textColor": textColor },
57
57
  dot && React.createElement(Dot, { "$secondaryColor": dotColor }),
58
58
  children,
59
- onDismiss && React.createElement(Close, { size: 16 })));
59
+ onDismiss && React.createElement(Close, { size: 16, onClick: onDismiss })));
60
60
  };
61
61
  const Component = styled.div `
62
62
  display: flex;
@@ -9,11 +9,13 @@ export type Props = {
9
9
  helperText?: string;
10
10
  label?: string;
11
11
  maxCharacters?: number;
12
+ multiple?: boolean;
12
13
  onChange?: React.ChangeEventHandler<HTMLInputElement>;
14
+ onMultipleChange?: (values: string[]) => void;
13
15
  placeholder?: string;
14
16
  size?: TextInputSize;
15
17
  sx?: string;
16
- value: string;
18
+ value: string | string[];
17
19
  };
18
20
  interface DisabledProps extends Props {
19
21
  disabled?: true;
@@ -31,5 +33,5 @@ interface WarningProps extends Props {
31
33
  warning?: true;
32
34
  }
33
35
  export type TextInputProps = DisabledProps | SuccessfulProps | WarningProps;
34
- export declare const TextInput: ({ bg, disabled, helperText, icon, label, maxCharacters, onChange, placeholder, size, successful, sx, value, warning, }: TextInputProps) => React.JSX.Element;
36
+ export declare const TextInput: ({ bg, disabled, helperText, icon, label, maxCharacters, multiple, onChange, onMultipleChange, placeholder, size, successful, sx, value, warning, }: TextInputProps) => React.JSX.Element;
35
37
  export {};
@@ -1,13 +1,57 @@
1
1
  'use client';
2
2
  import React from 'react';
3
3
  import styled from 'styled-components';
4
+ import { Chip } from '../../feedback/chip/chip';
4
5
  import { CheckmarkCircle, AlertCircle } from '../../../icons';
5
- export const TextInput = ({ bg = 'var(--color-blue-10)', disabled, helperText, icon, label, maxCharacters, onChange, placeholder, size = 'large', successful, sx, value, warning, }) => {
6
+ export const TextInput = ({ bg = 'var(--color-blue-10)', disabled, helperText, icon, label, maxCharacters, multiple, onChange, onMultipleChange, placeholder, size = 'large', successful, sx, value, warning, }) => {
7
+ const id = React.useId();
8
+ const isMultiple = multiple;
9
+ const [multipleValueToAdd, setMultipleValueToAdd] = React.useState('');
10
+ const handleMultipleValueToAdd = (event) => {
11
+ setMultipleValueToAdd(event.target.value);
12
+ };
13
+ /**
14
+ * when there is no text in the input,
15
+ * pop the previous multiple value out
16
+ */
17
+ const handleMultipleValueDelete = (event) => {
18
+ if (value.length &&
19
+ onMultipleChange &&
20
+ !multipleValueToAdd &&
21
+ (event.key === 'Delete' || event.key === 'Backspace')) {
22
+ onMultipleChange(value.slice(0, value.length - 1));
23
+ }
24
+ };
25
+ /**
26
+ * when a user presses enter (submit) add the input to the values
27
+ * but don't add the same value twice
28
+ */
29
+ const handleMultipleAdd = (event) => {
30
+ event.stopPropagation();
31
+ event.preventDefault();
32
+ const alreadyHasValue = value.includes(multipleValueToAdd);
33
+ if (onMultipleChange && !alreadyHasValue) {
34
+ onMultipleChange([...value, multipleValueToAdd]);
35
+ }
36
+ setMultipleValueToAdd('');
37
+ };
38
+ /**
39
+ * when the user clicks on the chip to remove it, remove it from the value
40
+ */
41
+ const handleMultipleItemRemoval = (removalItem) => {
42
+ onMultipleChange &&
43
+ onMultipleChange(value.filter((item) => item !== removalItem));
44
+ };
6
45
  return (React.createElement(Label, { "$disabled": disabled, "$size": size, "$sx": sx },
7
46
  label,
8
47
  React.createElement(InputWrapper, { "$bg": bg, "$size": size, "$successful": successful, "$warning": warning },
9
48
  icon,
10
- React.createElement(Input, { disabled: disabled, onChange: onChange, placeholder: placeholder, value: maxCharacters ? value.slice(0, maxCharacters - 1) : value, "$size": size }),
49
+ isMultiple && (React.createElement(MultipleInputWrapper, { onSubmit: handleMultipleAdd },
50
+ value.filter(Boolean).map((item, index) => (React.createElement(Chip, { key: id + item + index, color: "blue", size: "small", onDismiss: () => handleMultipleItemRemoval(item) }, item))),
51
+ React.createElement(Input, { onChange: handleMultipleValueToAdd, onKeyDown: handleMultipleValueDelete, value: multipleValueToAdd, "$size": size }))),
52
+ !isMultiple && (React.createElement(Input, { disabled: disabled, onChange: onChange, placeholder: placeholder, value: maxCharacters
53
+ ? value.slice(0, maxCharacters - 1)
54
+ : value, "$size": size })),
11
55
  maxCharacters && (React.createElement(MaxCharactersText, { "$size": size },
12
56
  value.length,
13
57
  " / ",
@@ -67,6 +111,7 @@ const Input = styled.input `
67
111
  font-family: Inter;
68
112
  font-size: ${({ $size }) => ($size === 'small' ? 14 : 16)}px;
69
113
  line-height: ${({ $size }) => ($size === 'small' ? 20 : 24)}px;
114
+ color: var(--color-grey-3);
70
115
  border: none;
71
116
  outline: none;
72
117
  border-radius: 8px;
@@ -90,3 +135,8 @@ const MaxCharactersText = styled.span `
90
135
  font-weight: 400;
91
136
  line-height: 20px;
92
137
  `;
138
+ const MultipleInputWrapper = styled.form `
139
+ display: flex;
140
+ flex-flow: row wrap;
141
+ gap: 8px 16px;
142
+ `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soul-refiner/design-system",
3
- "version": "0.2.19",
3
+ "version": "0.2.21",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "publishConfig": {