@codeleap/web 3.20.3 → 3.21.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/web",
3
- "version": "3.20.3",
3
+ "version": "3.21.0",
4
4
  "main": "src/index.ts",
5
5
  "repository": {
6
6
  "url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
@@ -23,11 +23,13 @@
23
23
  "@radix-ui/react-progress": "^1.0.3",
24
24
  "@radix-ui/react-slider": "1.1.1",
25
25
  "@radix-ui/react-tooltip": "^1.0.6",
26
+ "@tiptap/react": "2.1.16",
26
27
  "framer-motion": "^10.10.0",
27
28
  "js-cookie": "^3.0.1",
28
29
  "masonic": "^3.7.0",
29
30
  "rc-slider": "^9.7.5",
30
31
  "react-autosize-textarea": "^7.1.0",
32
+ "react-colorful": "^5.6.1",
31
33
  "react-datepicker": "^4.20.0",
32
34
  "react-circular-progressbar": "^2.1.0",
33
35
  "react-dropzone": "^14.2.3",
@@ -0,0 +1,93 @@
1
+ /* eslint-disable max-len */
2
+ import React, { useCallback } from 'react'
3
+ import { ActionIcon, Collapse, ColorPickerPresets, View } from '../components'
4
+ import { HexColorPicker } from 'react-colorful'
5
+ import { useBooleanToggle, useDefaultComponentStyle, useState } from '@codeleap/common'
6
+ import { ColorPickerProps, ColorTypes } from './types'
7
+
8
+ export * from './styles'
9
+ export * from './types'
10
+
11
+ const defaultProps = {
12
+ pickerComponent: (props) => <HexColorPicker {...props}/>,
13
+ icon: 'edit',
14
+ clearIcon: 'trash',
15
+ confirmIcon: 'check',
16
+ showFooter: true,
17
+ }
18
+
19
+ export const ColorPicker = (props: ColorPickerProps) => {
20
+ const {
21
+ isPlain = false,
22
+ initialColor,
23
+ showFooter,
24
+ icon,
25
+ clearIcon,
26
+ confirmIcon,
27
+ variants = [],
28
+ styles = {},
29
+ responsiveVariants = {},
30
+ onConfirm,
31
+ onClear,
32
+ closeOnConfirm = true,
33
+ pickerComponent: PickerComponent,
34
+ openPickerComponent: OpenPickerComponent,
35
+ footerComponent: FooterComponent = null,
36
+ openPickerProps,
37
+ } = props
38
+ const [visible, toggle] = useBooleanToggle(false)
39
+ const [color, setColor] = useState<ColorTypes>(initialColor)
40
+
41
+ const variantStyles = useDefaultComponentStyle<'u:ColorPicker', typeof ColorPickerPresets>('u:ColorPicker', {
42
+ variants,
43
+ styles,
44
+ responsiveVariants,
45
+ })
46
+
47
+ const handleConfirmation = useCallback(() => {
48
+ onConfirm?.(color)
49
+ closeOnConfirm && toggle(false)
50
+ }, [color])
51
+
52
+ const handleClear = useCallback(() => {
53
+ setColor(initialColor)
54
+ onClear?.()
55
+ }, [initialColor])
56
+
57
+ const Footer = useCallback(() => (
58
+ <View style={variantStyles.footerWrapper}>
59
+ <ActionIcon debugName='ColorPicker footer trash' name={clearIcon} onPress={handleClear} styles={variantStyles.footerButton} />
60
+ <ActionIcon debugName='ColorPicker footer check' name={confirmIcon} onPress={handleConfirmation} styles={variantStyles.footerButton} />
61
+ </View>
62
+ ), [clearIcon, confirmIcon, handleClear, handleConfirmation])
63
+
64
+ // Dragging to change the color in any other way does not seem to work for some reason.
65
+ const picker = <View style={variantStyles.picker}><PickerComponent color={color} onChange={setColor} /></View>
66
+
67
+ const _footer = !!showFooter && FooterComponent ? <FooterComponent color={color} handleConfirmation={handleConfirmation} handleClear={handleClear}/> : <Footer/>
68
+ const openColorPickerBtn = !!OpenPickerComponent ? <OpenPickerComponent color={color} visible={visible} toggle={toggle}/> : <ActionIcon onPress={toggle} icon={icon} {...openPickerProps}/>
69
+
70
+ return (
71
+ <View style={variantStyles.wrapper}>
72
+ {isPlain ? picker : (
73
+ <>
74
+ {openColorPickerBtn}
75
+ <Collapse
76
+ open={visible}
77
+ styles={{ wrapper: [
78
+ variantStyles.dropdown,
79
+ visible && variantStyles['dropdown:open'],
80
+ ] }}
81
+ >
82
+ <View style={variantStyles.dropdownInnerWrapper}>
83
+ {picker}
84
+ {_footer}
85
+ </View>
86
+ </Collapse>
87
+ </>
88
+ )}
89
+ </View>
90
+ )
91
+ }
92
+
93
+ ColorPicker.defaultProps = defaultProps
@@ -0,0 +1,13 @@
1
+ import { PartialComponentStyle, createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+ import { ActionIconComposition } from '../ActionIcon'
3
+
4
+ type ColorPickerState = 'open'
5
+ export type ColorPickerParts = 'wrapper' | 'picker' | 'dropdown' | `dropdown:${ColorPickerState}` | 'dropdownInnerWrapper' | 'footerWrapper'
6
+
7
+ export type ColorPickerComposition = {
8
+ footerButton?: PartialComponentStyle<ActionIconComposition, any>
9
+ } & {[x in ColorPickerParts]?: any}
10
+
11
+ const createColorPickerStyle = createDefaultVariantFactory<'', ColorPickerComposition>()
12
+
13
+ export const ColorPickerPresets = includePresets((styles) => createColorPickerStyle(() => ({ wrapper: styles })))
@@ -0,0 +1,25 @@
1
+ import React from 'react'
2
+ import { ActionIconProps, IconProps } from '../components'
3
+ import { RgbColor, RgbaColor, HslColor, HsvColor, HslaColor, HsvaColor } from 'react-colorful'
4
+ import { ComponentVariants } from '@codeleap/common'
5
+ import { ColorPickerComposition, ColorPickerPresets } from './styles'
6
+
7
+ export type ColorTypes = RgbColor | HslColor | HsvColor | RgbaColor | HslaColor | HsvaColor | string
8
+
9
+ export type ColorPickerProps = React.PropsWithChildren<{
10
+ styles?: ColorPickerComposition
11
+ style?: React.CSSProperties
12
+ isPlain?: boolean
13
+ closeOnConfirm?: boolean
14
+ initialColor?: ColorTypes
15
+ showFooter?: boolean
16
+ icon?: IconProps['name']
17
+ clearIcon?: IconProps['name']
18
+ confirmIcon?: IconProps['name']
19
+ openPickerProps?: ActionIconProps
20
+ onConfirm?: (color: ColorTypes) => void
21
+ onClear?: () => void
22
+ openPickerComponent?: (props: { color: ColorTypes; visible: boolean; toggle: (v?: boolean) => void }) => JSX.Element
23
+ pickerComponent?: (props: any) => JSX.Element
24
+ footerComponent?: (props: {color: string | RgbColor | RgbColor; handleConfirmation: () => void; handleClear: () => void}) => JSX.Element
25
+ } & ComponentVariants<typeof ColorPickerPresets>>
@@ -0,0 +1,62 @@
1
+ import { useCallback, useDefaultComponentStyle } from '@codeleap/common'
2
+ import { BubbleMenu, FloatingMenu, EditorContent } from '@tiptap/react'
3
+ import { FileInput, View } from '../components'
4
+ import { TextEditorProps } from './types'
5
+ import { TextEditorPresets } from './styles'
6
+
7
+ export * from './styles'
8
+ export * from './types'
9
+
10
+ export const TextEditor = (props: TextEditorProps) => {
11
+ const {
12
+ children,
13
+ editor,
14
+ variants = [],
15
+ styles = {},
16
+ responsiveVariants = {},
17
+ style = {},
18
+ bubbleMenuProps,
19
+ floatingMenuProps,
20
+ toolbarComponent,
21
+ fileInputRef,
22
+ } = props
23
+ const variantStyles = useDefaultComponentStyle<'u:TextEditor', typeof TextEditorPresets>('u:TextEditor', {
24
+ variants,
25
+ styles,
26
+ responsiveVariants,
27
+ })
28
+
29
+ const _BubbleMenu = useCallback(() => {
30
+ return (
31
+ <BubbleMenu css={[variantStyles.bubbleMenu]} {...bubbleMenuProps} editor={editor}>
32
+ <View style={variantStyles.bubbleMenuInnerWrapper}>
33
+ {bubbleMenuProps?.renderContent}
34
+ </View>
35
+ </BubbleMenu>
36
+ )
37
+ }, [editor])
38
+
39
+ const _FloatingMenu = useCallback(() => {
40
+ return (
41
+ <FloatingMenu css={[variantStyles.floatingMenu]} {...floatingMenuProps} editor={editor}>
42
+ <View style={variantStyles.floatingMenuInnerWrapper}>
43
+ {floatingMenuProps?.renderContent}
44
+ </View>
45
+ </FloatingMenu>
46
+ )
47
+ }, [editor])
48
+
49
+ if (!editor) return null
50
+ return (
51
+ <View style={{ ...variantStyles.wrapper, ...style }}>
52
+ {toolbarComponent}
53
+ {children}
54
+ <_BubbleMenu/>
55
+ <_FloatingMenu/>
56
+ <EditorContent editor={editor}/>
57
+ <FileInput
58
+ ref={fileInputRef}
59
+ />
60
+ </View>
61
+ )
62
+ }
@@ -0,0 +1,7 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+
3
+ export type TextEditorComposition = 'wrapper' | 'floatingMenu' | 'bubbleMenu' | 'bubbleMenuInnerWrapper' | 'floatingMenuInnerWrapper'
4
+
5
+ const createTextEditorStyle = createDefaultVariantFactory<TextEditorComposition>()
6
+
7
+ export const TextEditorPresets = includePresets((styles) => createTextEditorStyle(() => ({ wrapper: styles })))
@@ -0,0 +1,15 @@
1
+ import { RefObject } from 'react'
2
+ import { ComponentVariants, StylesOf } from '@codeleap/common'
3
+ import { BubbleMenuProps, Editor, FloatingMenuProps } from '@tiptap/react'
4
+ import { FileInputRef } from '../FileInput'
5
+ import { TextEditorComposition, TextEditorPresets } from './styles'
6
+
7
+ export type TextEditorProps = React.PropsWithChildren<{
8
+ editor: Editor
9
+ styles?: StylesOf<TextEditorComposition>
10
+ style?: React.CSSProperties
11
+ bubbleMenuProps?: BubbleMenuProps & {renderContent: React.ReactNode}
12
+ floatingMenuProps?: FloatingMenuProps & {renderContent: React.ReactNode}
13
+ toolbarComponent?: JSX.Element
14
+ fileInputRef?: RefObject<FileInputRef>
15
+ } & ComponentVariants<typeof TextEditorPresets>>
@@ -35,5 +35,7 @@ export * from './DatePicker'
35
35
  export * from './Dropzone'
36
36
  export * from './Progress'
37
37
  export * from './Tag'
38
+ export * from './TextEditor'
39
+ export * from './ColorPicker'
38
40
 
39
41
  export * from './defaultStyles'