@helpwave/hightide 0.0.1
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/.storybook/main.ts +24 -0
- package/.storybook/preview.tsx +67 -0
- package/LICENSE +373 -0
- package/README.md +8 -0
- package/coloring/shading.ts +46 -0
- package/coloring/types.ts +13 -0
- package/components/Avatar.tsx +58 -0
- package/components/AvatarGroup.tsx +48 -0
- package/components/BreadCrumb.tsx +35 -0
- package/components/Button.tsx +236 -0
- package/components/ChipList.tsx +89 -0
- package/components/Circle.tsx +27 -0
- package/components/ErrorComponent.tsx +40 -0
- package/components/Expandable.tsx +61 -0
- package/components/HelpwaveBadge.tsx +35 -0
- package/components/HideableContentSection.tsx +43 -0
- package/components/InputGroup.tsx +72 -0
- package/components/LoadingAndErrorComponent.tsx +47 -0
- package/components/LoadingAnimation.tsx +40 -0
- package/components/LoadingButton.tsx +27 -0
- package/components/MarkdownInterpreter.tsx +278 -0
- package/components/Pagination.tsx +65 -0
- package/components/Profile.tsx +124 -0
- package/components/ProgressIndicator.tsx +58 -0
- package/components/Ring.tsx +286 -0
- package/components/SearchableList.tsx +69 -0
- package/components/SortButton.tsx +33 -0
- package/components/Span.tsx +0 -0
- package/components/StepperBar.tsx +124 -0
- package/components/Table.tsx +330 -0
- package/components/TechRadar.tsx +247 -0
- package/components/TextImage.tsx +86 -0
- package/components/TimeDisplay.tsx +121 -0
- package/components/Tooltip.tsx +92 -0
- package/components/VerticalDivider.tsx +51 -0
- package/components/date/DatePicker.tsx +164 -0
- package/components/date/DayPicker.tsx +95 -0
- package/components/date/TimePicker.tsx +167 -0
- package/components/date/YearMonthPicker.tsx +130 -0
- package/components/examples/InputGroupExample.tsx +58 -0
- package/components/examples/MultiSelectExample.tsx +57 -0
- package/components/examples/SearchableSelectExample.tsx +34 -0
- package/components/examples/SelectExample.tsx +28 -0
- package/components/examples/StackingModals.tsx +54 -0
- package/components/examples/TableExample.tsx +159 -0
- package/components/examples/TextareaExample.tsx +23 -0
- package/components/examples/TileExample.tsx +25 -0
- package/components/examples/Title.tsx +0 -0
- package/components/examples/date/DateTimePickerExample.tsx +53 -0
- package/components/examples/properties/CheckboxPropertyExample.tsx +29 -0
- package/components/examples/properties/DatePropertyExample.tsx +44 -0
- package/components/examples/properties/MultiSelectPropertyExample.tsx +39 -0
- package/components/examples/properties/NumberPropertyExample.tsx +28 -0
- package/components/examples/properties/SelectPropertyExample.tsx +39 -0
- package/components/examples/properties/TextPropertyExample.tsx +30 -0
- package/components/icons/Helpwave.tsx +51 -0
- package/components/icons/Tag.tsx +29 -0
- package/components/layout/Carousel.tsx +396 -0
- package/components/layout/DividerInserter.tsx +37 -0
- package/components/layout/FAQSection.tsx +57 -0
- package/components/layout/Tile.tsx +67 -0
- package/components/modals/ConfirmDialog.tsx +105 -0
- package/components/modals/DiscardChangesDialog.tsx +71 -0
- package/components/modals/InputModal.tsx +26 -0
- package/components/modals/LanguageModal.tsx +76 -0
- package/components/modals/Modal.tsx +149 -0
- package/components/modals/ModalRegister.tsx +45 -0
- package/components/properties/CheckboxProperty.tsx +62 -0
- package/components/properties/DateProperty.tsx +58 -0
- package/components/properties/MultiSelectProperty.tsx +82 -0
- package/components/properties/NumberProperty.tsx +86 -0
- package/components/properties/PropertyBase.tsx +84 -0
- package/components/properties/SelectProperty.tsx +67 -0
- package/components/properties/TextProperty.tsx +81 -0
- package/components/user-input/Checkbox.tsx +139 -0
- package/components/user-input/DateAndTimePicker.tsx +156 -0
- package/components/user-input/Input.tsx +192 -0
- package/components/user-input/Label.tsx +32 -0
- package/components/user-input/Menu.tsx +75 -0
- package/components/user-input/MultiSelect.tsx +158 -0
- package/components/user-input/ScrollPicker.tsx +240 -0
- package/components/user-input/SearchableSelect.tsx +36 -0
- package/components/user-input/Select.tsx +132 -0
- package/components/user-input/Textarea.tsx +86 -0
- package/components/user-input/ToggleableInput.tsx +115 -0
- package/eslint.config.js +3 -0
- package/globals.css +488 -0
- package/hooks/useHoverState.ts +88 -0
- package/hooks/useLanguage.tsx +78 -0
- package/hooks/useLocalStorage.tsx +33 -0
- package/hooks/useOutsideClick.ts +25 -0
- package/hooks/useSaveDelay.ts +46 -0
- package/hooks/useTheme.tsx +57 -0
- package/hooks/useTranslation.ts +43 -0
- package/index.ts +0 -0
- package/package.json +71 -0
- package/postcss.config.mjs +7 -0
- package/stories/README.md +23 -0
- package/stories/coloring/shading.stories.tsx +54 -0
- package/stories/geometry/Circle.stories.tsx +16 -0
- package/stories/geometry/rings/AnimatedRing.stories.tsx +18 -0
- package/stories/geometry/rings/RadialRings.stories.tsx +19 -0
- package/stories/geometry/rings/Ring.stories.tsx +17 -0
- package/stories/geometry/rings/RingWave.stories.tsx +20 -0
- package/stories/layout/FAQSection.stories.tsx +49 -0
- package/stories/layout/InputGroup.stories.tsx +19 -0
- package/stories/layout/Table.stories.tsx +19 -0
- package/stories/layout/TextImage.stories.tsx +24 -0
- package/stories/layout/chip/Chip.stories.tsx +19 -0
- package/stories/layout/chip/ChipList.stories.tsx +27 -0
- package/stories/layout/tile/Tile.stories.ts +20 -0
- package/stories/layout/tile/TileWithImage.stories.tsx +27 -0
- package/stories/other/BreadCrumbs.stories.tsx +21 -0
- package/stories/other/HelpwaveBadge.stories.tsx +18 -0
- package/stories/other/HelpwaveSpinner.stories.tsx +19 -0
- package/stories/other/MarkdownInterpreter.stories.tsx +18 -0
- package/stories/other/Profile.stories.tsx +52 -0
- package/stories/other/SearchableList.stories.tsx +21 -0
- package/stories/other/StackingModals.stories.tsx +16 -0
- package/stories/other/TechRadar.stories.tsx +14 -0
- package/stories/other/Translation.stories.tsx +56 -0
- package/stories/other/VerticalDivider.stories.tsx +20 -0
- package/stories/other/avatar/Avatar.stories.tsx +19 -0
- package/stories/other/avatar/AvatarGroup.stories.tsx +26 -0
- package/stories/other/tooltip/Tooltip.stories.tsx +30 -0
- package/stories/other/tooltip/TooltipStack.stories.tsx +39 -0
- package/stories/user-action/button/LoadingButton.stories.tsx +21 -0
- package/stories/user-action/button/OutlineButton.stories.tsx +22 -0
- package/stories/user-action/button/SolidButton.stories.tsx +22 -0
- package/stories/user-action/button/TextButton.stories.tsx +22 -0
- package/stories/user-action/input/Checkbox.stories.tsx +20 -0
- package/stories/user-action/input/Label.stories.tsx +18 -0
- package/stories/user-action/input/ScrollPicker.stories.tsx +20 -0
- package/stories/user-action/input/Textarea.stories.tsx +22 -0
- package/stories/user-action/input/date/DatePicker.stories.tsx +23 -0
- package/stories/user-action/input/date/DateTimePicker.stories.tsx +26 -0
- package/stories/user-action/input/date/DayPicker.stories.tsx +20 -0
- package/stories/user-action/input/date/TimePicker.stories.tsx +20 -0
- package/stories/user-action/input/date/YearMonthPicker.stories.tsx +21 -0
- package/stories/user-action/input/select/MultiSelect.stories.tsx +39 -0
- package/stories/user-action/input/select/SearchableSelect.stories.tsx +32 -0
- package/stories/user-action/input/select/Select.stories.tsx +30 -0
- package/stories/user-action/properties/CheckboxProperty.stories.tsx +20 -0
- package/stories/user-action/properties/DateProperty.stories.tsx +21 -0
- package/stories/user-action/properties/MultiSelectProperty.stories.tsx +33 -0
- package/stories/user-action/properties/NumberProperty.stories.tsx +21 -0
- package/stories/user-action/properties/PropertyBase.stories.tsx +28 -0
- package/stories/user-action/properties/SingleSelectProperty.stories.tsx +35 -0
- package/stories/user-action/properties/TextProperty.stories.tsx +20 -0
- package/tsconfig.json +20 -0
- package/util/array.ts +115 -0
- package/util/builder.ts +9 -0
- package/util/date.ts +180 -0
- package/util/easeFunctions.ts +37 -0
- package/util/emailValidation.ts +3 -0
- package/util/loopingArray.ts +94 -0
- package/util/math.ts +3 -0
- package/util/news.ts +43 -0
- package/util/noop.ts +1 -0
- package/util/simpleSearch.ts +65 -0
- package/util/storage.ts +37 -0
- package/util/types.ts +4 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { CalendarDays } from 'lucide-react'
|
|
2
|
+
import clsx from 'clsx'
|
|
3
|
+
import { formatDate, formatDateTime } from '../../util/date'
|
|
4
|
+
import { noop } from '../../util/noop'
|
|
5
|
+
import { Input } from '../user-input/Input'
|
|
6
|
+
import type { PropertyBaseProps } from './PropertyBase'
|
|
7
|
+
import { PropertyBase } from './PropertyBase'
|
|
8
|
+
|
|
9
|
+
export type DatePropertyProps = Omit<PropertyBaseProps, 'icon' | 'input' | 'hasValue'> & {
|
|
10
|
+
value?: Date,
|
|
11
|
+
onChange?: (date: Date) => void,
|
|
12
|
+
onEditComplete?: (value: Date) => void,
|
|
13
|
+
type?: 'dateTime' | 'date',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* An Input for date properties
|
|
18
|
+
*/
|
|
19
|
+
export const DateProperty = ({
|
|
20
|
+
value,
|
|
21
|
+
onChange = noop,
|
|
22
|
+
onEditComplete = noop,
|
|
23
|
+
readOnly,
|
|
24
|
+
type = 'dateTime',
|
|
25
|
+
...baseProps
|
|
26
|
+
}: DatePropertyProps) => {
|
|
27
|
+
const hasValue = !!value
|
|
28
|
+
|
|
29
|
+
const dateText = value ? (type === 'dateTime' ? formatDateTime(value) : formatDate(value)) : ''
|
|
30
|
+
return (
|
|
31
|
+
<PropertyBase
|
|
32
|
+
{...baseProps}
|
|
33
|
+
hasValue={hasValue}
|
|
34
|
+
icon={<CalendarDays size={16}/>}
|
|
35
|
+
input={({ softRequired }) => (
|
|
36
|
+
<div
|
|
37
|
+
className={clsx('row grow py-2 px-4 cursor-pointer', { 'text-warning': softRequired && !hasValue })}
|
|
38
|
+
>
|
|
39
|
+
<Input
|
|
40
|
+
className={clsx('!ring-0 !border-0 !outline-0 !p-0 !m-0 !shadow-none !w-fit !rounded-none', { 'bg-surface-warning': softRequired && !hasValue })}
|
|
41
|
+
value={dateText}
|
|
42
|
+
type={type === 'dateTime' ? 'datetime-local' : 'date'}
|
|
43
|
+
readOnly={readOnly}
|
|
44
|
+
onChange={(value, event) => {
|
|
45
|
+
if (!event.target.value) {
|
|
46
|
+
event.preventDefault()
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
const dueDate = new Date(value)
|
|
50
|
+
onChange(dueDate)
|
|
51
|
+
}}
|
|
52
|
+
onEditCompleted={(value) => onEditComplete(new Date(value))}
|
|
53
|
+
/>
|
|
54
|
+
</div>
|
|
55
|
+
)}
|
|
56
|
+
/>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { List } from 'lucide-react'
|
|
2
|
+
import clsx from 'clsx'
|
|
3
|
+
import type { Languages } from '../../hooks/useLanguage'
|
|
4
|
+
import type { PropsForTranslation } from '../../hooks/useTranslation'
|
|
5
|
+
import { useTranslation } from '../../hooks/useTranslation'
|
|
6
|
+
import type { MultiSelectProps } from '../user-input/MultiSelect'
|
|
7
|
+
import { MultiSelect } from '../user-input/MultiSelect'
|
|
8
|
+
import { ChipList } from '../ChipList'
|
|
9
|
+
import type { PropertyBaseProps } from './PropertyBase'
|
|
10
|
+
import { PropertyBase } from './PropertyBase'
|
|
11
|
+
|
|
12
|
+
type MultiSelectPropertyTranslation = {
|
|
13
|
+
select: string,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const defaultMultiSelectPropertyTranslation: Record<Languages, MultiSelectPropertyTranslation> = {
|
|
17
|
+
en: {
|
|
18
|
+
select: 'Select'
|
|
19
|
+
},
|
|
20
|
+
de: {
|
|
21
|
+
select: 'Auswählen'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type MultiSelectPropertyProps<T> =
|
|
26
|
+
Omit<PropertyBaseProps & MultiSelectProps<T>, 'icon' | 'input' | 'hasValue' | 'className' | 'disabled' | 'label' | 'triggerClassName'>
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An Input for MultiSelect properties
|
|
30
|
+
*/
|
|
31
|
+
export const MultiSelectProperty = <T, >({
|
|
32
|
+
overwriteTranslation,
|
|
33
|
+
options,
|
|
34
|
+
name,
|
|
35
|
+
readOnly = false,
|
|
36
|
+
softRequired,
|
|
37
|
+
onRemove,
|
|
38
|
+
...multiSelectProps
|
|
39
|
+
}: PropsForTranslation<MultiSelectPropertyTranslation, MultiSelectPropertyProps<T>>) => {
|
|
40
|
+
const translation = useTranslation(defaultMultiSelectPropertyTranslation, overwriteTranslation)
|
|
41
|
+
const hasValue = options.some(value => value.selected)
|
|
42
|
+
let triggerClassName: string
|
|
43
|
+
if (softRequired && !hasValue) {
|
|
44
|
+
triggerClassName = 'border-warning hover:brightness-90'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<PropertyBase
|
|
49
|
+
name={name}
|
|
50
|
+
onRemove={onRemove}
|
|
51
|
+
readOnly={readOnly}
|
|
52
|
+
softRequired={softRequired}
|
|
53
|
+
hasValue={hasValue}
|
|
54
|
+
icon={<List size={16}/>}
|
|
55
|
+
input={({ softRequired }) => (
|
|
56
|
+
<div
|
|
57
|
+
className={clsx('row grow py-2 px-4 cursor-pointer', { 'text-warning': softRequired && !hasValue })}
|
|
58
|
+
>
|
|
59
|
+
<MultiSelect
|
|
60
|
+
{...multiSelectProps}
|
|
61
|
+
className={clsx('w-full', { 'bg-surface-warning': softRequired && !hasValue })}
|
|
62
|
+
triggerClassName={triggerClassName}
|
|
63
|
+
selectedDisplay={({ items }) => {
|
|
64
|
+
const selected = items.filter(value => value.selected)
|
|
65
|
+
if (selected.length === 0) {
|
|
66
|
+
return (<span>Select</span>)
|
|
67
|
+
}
|
|
68
|
+
return (
|
|
69
|
+
<ChipList
|
|
70
|
+
list={selected.map(value => ({ children: value.label }))}
|
|
71
|
+
/>
|
|
72
|
+
)
|
|
73
|
+
}}
|
|
74
|
+
options={options}
|
|
75
|
+
disabled={readOnly}
|
|
76
|
+
hintText={`${translation.select}...`}
|
|
77
|
+
/>
|
|
78
|
+
</div>
|
|
79
|
+
)}
|
|
80
|
+
/>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Binary } from 'lucide-react'
|
|
2
|
+
import clsx from 'clsx'
|
|
3
|
+
import { noop } from '../../util/noop'
|
|
4
|
+
import { Input } from '../user-input/Input'
|
|
5
|
+
import type { Languages } from '../../hooks/useLanguage'
|
|
6
|
+
import type { PropsForTranslation } from '../../hooks/useTranslation'
|
|
7
|
+
import { useTranslation } from '../../hooks/useTranslation'
|
|
8
|
+
import type { PropertyBaseProps } from './PropertyBase'
|
|
9
|
+
import { PropertyBase } from './PropertyBase'
|
|
10
|
+
|
|
11
|
+
type NumberPropertyTranslation = {
|
|
12
|
+
value: string,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const defaultNumberPropertyTranslation: Record<Languages, NumberPropertyTranslation> = {
|
|
16
|
+
en: {
|
|
17
|
+
value: 'Value'
|
|
18
|
+
},
|
|
19
|
+
de: {
|
|
20
|
+
value: 'Wert'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type NumberPropertyProps = Omit<PropertyBaseProps, 'icon' | 'input' | 'hasValue'> & {
|
|
25
|
+
value?: number,
|
|
26
|
+
suffix?: string,
|
|
27
|
+
onChange?: (value: number) => void,
|
|
28
|
+
onEditComplete?: (value: number) => void,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* An Input for number properties
|
|
33
|
+
*/
|
|
34
|
+
export const NumberProperty = ({
|
|
35
|
+
overwriteTranslation,
|
|
36
|
+
value,
|
|
37
|
+
onChange = noop,
|
|
38
|
+
onRemove = noop,
|
|
39
|
+
onEditComplete = noop,
|
|
40
|
+
readOnly,
|
|
41
|
+
suffix,
|
|
42
|
+
...baseProps
|
|
43
|
+
}: PropsForTranslation<NumberPropertyTranslation, NumberPropertyProps>) => {
|
|
44
|
+
const translation = useTranslation(defaultNumberPropertyTranslation, overwriteTranslation)
|
|
45
|
+
const hasValue = value !== undefined
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<PropertyBase
|
|
49
|
+
{...baseProps}
|
|
50
|
+
onRemove={onRemove}
|
|
51
|
+
hasValue={hasValue}
|
|
52
|
+
icon={<Binary size={16}/>}
|
|
53
|
+
input={({ softRequired }) => (
|
|
54
|
+
<div
|
|
55
|
+
className={clsx('row grow py-2 px-4 cursor-pointer', { 'text-warning': softRequired && !hasValue })}
|
|
56
|
+
>
|
|
57
|
+
<Input
|
|
58
|
+
expanded={false}
|
|
59
|
+
className={clsx('!ring-0 !border-0 !outline-0 !p-0 !m-0 !w-fit !shadow-none !rounded-none', { 'bg-surface-warning placeholder-warning': softRequired && !hasValue })}
|
|
60
|
+
value={value?.toString() ?? ''}
|
|
61
|
+
type="number"
|
|
62
|
+
readOnly={readOnly}
|
|
63
|
+
placeholder={`${translation.value}...`}
|
|
64
|
+
onChange={(value) => {
|
|
65
|
+
const numberValue = parseFloat(value)
|
|
66
|
+
if (isNaN(numberValue)) {
|
|
67
|
+
onRemove()
|
|
68
|
+
} else {
|
|
69
|
+
onChange(numberValue)
|
|
70
|
+
}
|
|
71
|
+
}}
|
|
72
|
+
onEditCompleted={(value) => {
|
|
73
|
+
const numberValue = parseFloat(value)
|
|
74
|
+
if (isNaN(numberValue)) {
|
|
75
|
+
onRemove()
|
|
76
|
+
} else {
|
|
77
|
+
onEditComplete(numberValue)
|
|
78
|
+
}
|
|
79
|
+
}}
|
|
80
|
+
/>
|
|
81
|
+
{suffix && <span className={clsx('ml-1', { 'bg-surface-warning': softRequired && !hasValue })}>{suffix}</span>}
|
|
82
|
+
</div>
|
|
83
|
+
)}
|
|
84
|
+
/>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import { AlertTriangle } from 'lucide-react'
|
|
3
|
+
import clsx from 'clsx'
|
|
4
|
+
import type { Languages } from '../../hooks/useLanguage'
|
|
5
|
+
import { TextButton } from '../Button'
|
|
6
|
+
import type { PropsForTranslation } from '../../hooks/useTranslation'
|
|
7
|
+
import { useTranslation } from '../../hooks/useTranslation'
|
|
8
|
+
|
|
9
|
+
type PropertyBaseTranslation = {
|
|
10
|
+
remove: string,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const defaultPropertyBaseTranslation: Record<Languages, PropertyBaseTranslation> = {
|
|
14
|
+
en: {
|
|
15
|
+
remove: 'Remove'
|
|
16
|
+
},
|
|
17
|
+
de: {
|
|
18
|
+
remove: 'Entfernen'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type PropertyBaseProps = {
|
|
23
|
+
name: string,
|
|
24
|
+
input: (props: { softRequired: boolean, hasValue: boolean }) => ReactNode,
|
|
25
|
+
onRemove?: () => void,
|
|
26
|
+
hasValue: boolean,
|
|
27
|
+
softRequired?: boolean,
|
|
28
|
+
readOnly?: boolean,
|
|
29
|
+
icon?: ReactNode,
|
|
30
|
+
className?: string,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A component for showing a properties with uniform styling
|
|
35
|
+
*/
|
|
36
|
+
export const PropertyBase = ({
|
|
37
|
+
overwriteTranslation,
|
|
38
|
+
name,
|
|
39
|
+
input,
|
|
40
|
+
softRequired = false,
|
|
41
|
+
hasValue,
|
|
42
|
+
icon,
|
|
43
|
+
readOnly,
|
|
44
|
+
onRemove,
|
|
45
|
+
className = '',
|
|
46
|
+
}: PropsForTranslation<PropertyBaseTranslation, PropertyBaseProps>) => {
|
|
47
|
+
const translation = useTranslation(defaultPropertyBaseTranslation, overwriteTranslation)
|
|
48
|
+
const requiredAndNoValue = softRequired && !hasValue
|
|
49
|
+
return (
|
|
50
|
+
<div className={clsx('row gap-x-0 group', className)}>
|
|
51
|
+
<div
|
|
52
|
+
className={
|
|
53
|
+
clsx('row gap-x-2 !w-[200px] px-4 py-2 items-center rounded-l-xl border-2 border-r-0', {
|
|
54
|
+
'bg-gray-100 text-black group-hover:border-primary border-gray-400': !requiredAndNoValue,
|
|
55
|
+
'bg-warning text-surface-warning group-hover:border-warning border-warning/90': requiredAndNoValue,
|
|
56
|
+
}, className)}
|
|
57
|
+
>
|
|
58
|
+
{icon}
|
|
59
|
+
{name}
|
|
60
|
+
</div>
|
|
61
|
+
<div className={
|
|
62
|
+
clsx('row grow justify-between items-center rounded-r-xl border-2 border-l-0', {
|
|
63
|
+
'bg-white group-hover:border-primary border-gray-400': !requiredAndNoValue,
|
|
64
|
+
'bg-surface-warning group-hover:border-warning border-warning/90': requiredAndNoValue,
|
|
65
|
+
}, className)}
|
|
66
|
+
>
|
|
67
|
+
{input({ softRequired, hasValue })}
|
|
68
|
+
{requiredAndNoValue && (
|
|
69
|
+
<div className="text-warning pr-4"><AlertTriangle size={24}/></div>
|
|
70
|
+
)}
|
|
71
|
+
{onRemove && (
|
|
72
|
+
<TextButton
|
|
73
|
+
onClick={onRemove}
|
|
74
|
+
color="negative"
|
|
75
|
+
className={clsx('pr-4 items-center', { '!text-transparent': !hasValue || readOnly })}
|
|
76
|
+
disabled={!hasValue || readOnly}
|
|
77
|
+
>
|
|
78
|
+
{translation.remove}
|
|
79
|
+
</TextButton>
|
|
80
|
+
)}
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { List } from 'lucide-react'
|
|
2
|
+
import clsx from 'clsx'
|
|
3
|
+
import type { Languages } from '../../hooks/useLanguage'
|
|
4
|
+
import type { PropsForTranslation } from '../../hooks/useTranslation'
|
|
5
|
+
import { useTranslation } from '../../hooks/useTranslation'
|
|
6
|
+
import type { SearchableSelectProps } from '../user-input/SearchableSelect'
|
|
7
|
+
import { SearchableSelect } from '../user-input/SearchableSelect'
|
|
8
|
+
import type { PropertyBaseProps } from './PropertyBase'
|
|
9
|
+
import { PropertyBase } from './PropertyBase'
|
|
10
|
+
|
|
11
|
+
type SingleSelectPropertyTranslation = {
|
|
12
|
+
select: string,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const defaultSingleSelectPropertyTranslation: Record<Languages, SingleSelectPropertyTranslation> = {
|
|
16
|
+
en: {
|
|
17
|
+
select: 'Select'
|
|
18
|
+
},
|
|
19
|
+
de: {
|
|
20
|
+
select: 'Auswählen'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type SingleSelectPropertyProps<T> =
|
|
25
|
+
Omit<PropertyBaseProps & SearchableSelectProps<T>, 'icon' | 'input' | 'hasValue' | 'className' | 'disabled' | 'label' | 'labelClassName' | 'additionalItems'>
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* An Input for SingleSelect properties
|
|
29
|
+
*/
|
|
30
|
+
export const SingleSelectProperty = <T, >({
|
|
31
|
+
overwriteTranslation,
|
|
32
|
+
value,
|
|
33
|
+
options,
|
|
34
|
+
name,
|
|
35
|
+
readOnly = false,
|
|
36
|
+
softRequired,
|
|
37
|
+
onRemove,
|
|
38
|
+
...multiSelectProps
|
|
39
|
+
}: PropsForTranslation<SingleSelectPropertyTranslation, SingleSelectPropertyProps<T>>) => {
|
|
40
|
+
const translation = useTranslation(defaultSingleSelectPropertyTranslation, overwriteTranslation)
|
|
41
|
+
const hasValue = value !== undefined
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<PropertyBase
|
|
45
|
+
name={name}
|
|
46
|
+
onRemove={onRemove}
|
|
47
|
+
readOnly={readOnly}
|
|
48
|
+
softRequired={softRequired}
|
|
49
|
+
hasValue={hasValue}
|
|
50
|
+
icon={<List size={16}/>}
|
|
51
|
+
input={({ softRequired }) => (
|
|
52
|
+
<div
|
|
53
|
+
className={clsx('row grow py-2 px-4 cursor-pointer', { 'text-warning': softRequired && !hasValue })}
|
|
54
|
+
>
|
|
55
|
+
<SearchableSelect
|
|
56
|
+
{...multiSelectProps}
|
|
57
|
+
value={value}
|
|
58
|
+
options={options}
|
|
59
|
+
isDisabled={readOnly}
|
|
60
|
+
className={clsx('w-full', { 'bg-surface-warning': softRequired && !hasValue })}
|
|
61
|
+
hintText={`${translation.select}...`}
|
|
62
|
+
/>
|
|
63
|
+
</div>
|
|
64
|
+
)}
|
|
65
|
+
/>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Text } from 'lucide-react'
|
|
2
|
+
import clsx from 'clsx'
|
|
3
|
+
import type { Languages } from '../../hooks/useLanguage'
|
|
4
|
+
import type { PropsForTranslation } from '../../hooks/useTranslation'
|
|
5
|
+
import { useTranslation } from '../../hooks/useTranslation'
|
|
6
|
+
import { Textarea } from '../user-input/Textarea'
|
|
7
|
+
import { noop } from '../../util/noop'
|
|
8
|
+
import type { PropertyBaseProps } from './PropertyBase'
|
|
9
|
+
import { PropertyBase } from './PropertyBase'
|
|
10
|
+
|
|
11
|
+
type TextPropertyTranslation = {
|
|
12
|
+
value: string,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const defaultTextPropertyTranslation: Record<Languages, TextPropertyTranslation> = {
|
|
16
|
+
en: {
|
|
17
|
+
value: 'Text'
|
|
18
|
+
},
|
|
19
|
+
de: {
|
|
20
|
+
value: 'Text'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type TextPropertyProps = Omit<PropertyBaseProps, 'icon' | 'input' | 'hasValue'> & {
|
|
25
|
+
value?: string,
|
|
26
|
+
onChange?: (value: string) => void,
|
|
27
|
+
onEditComplete?: (value: string) => void,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* An Input for Text properties
|
|
32
|
+
*/
|
|
33
|
+
export const TextProperty = ({
|
|
34
|
+
overwriteTranslation,
|
|
35
|
+
value,
|
|
36
|
+
readOnly,
|
|
37
|
+
onChange = noop,
|
|
38
|
+
onRemove = noop,
|
|
39
|
+
onEditComplete = noop,
|
|
40
|
+
...baseProps
|
|
41
|
+
}: PropsForTranslation<TextPropertyTranslation, TextPropertyProps>) => {
|
|
42
|
+
const translation = useTranslation(defaultTextPropertyTranslation, overwriteTranslation)
|
|
43
|
+
const hasValue = value !== undefined
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<PropertyBase
|
|
47
|
+
{...baseProps}
|
|
48
|
+
onRemove={onRemove}
|
|
49
|
+
hasValue={hasValue}
|
|
50
|
+
icon={<Text size={16} />}
|
|
51
|
+
input={({ softRequired }) => (
|
|
52
|
+
<div
|
|
53
|
+
className={clsx('row grow pt-2 pb-1 px-4 cursor-pointer', { 'text-warning': softRequired && !hasValue })}
|
|
54
|
+
>
|
|
55
|
+
<Textarea
|
|
56
|
+
className={clsx('!ring-0 !border-0 !outline-0 !p-0 !m-0 !shadow-none !rounded-none', { 'bg-surface-warning placeholder-warning': softRequired && !hasValue })}
|
|
57
|
+
rows={5}
|
|
58
|
+
defaultStyle={false}
|
|
59
|
+
value={value ?? ''}
|
|
60
|
+
readOnly={readOnly}
|
|
61
|
+
placeholder={`${translation.value}...`}
|
|
62
|
+
onChange={(value) => {
|
|
63
|
+
if (!value) {
|
|
64
|
+
onRemove()
|
|
65
|
+
} else {
|
|
66
|
+
onChange(value)
|
|
67
|
+
}
|
|
68
|
+
}}
|
|
69
|
+
onEditCompleted={(value) => {
|
|
70
|
+
if (!value) {
|
|
71
|
+
onRemove()
|
|
72
|
+
} else {
|
|
73
|
+
onEditComplete(value)
|
|
74
|
+
}
|
|
75
|
+
}}
|
|
76
|
+
/>
|
|
77
|
+
</div>
|
|
78
|
+
)}
|
|
79
|
+
/>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import * as CheckboxPrimitive from '@radix-ui/react-checkbox'
|
|
3
|
+
import type { CheckedState } from '@radix-ui/react-checkbox'
|
|
4
|
+
import { Check, Minus } from 'lucide-react'
|
|
5
|
+
import clsx from 'clsx'
|
|
6
|
+
import type { LabelProps } from './Label'
|
|
7
|
+
import { Label } from './Label'
|
|
8
|
+
|
|
9
|
+
type CheckBoxSize = 'small' | 'medium' | 'large'
|
|
10
|
+
|
|
11
|
+
const checkboxSizeMapping: Record<CheckBoxSize, string> = {
|
|
12
|
+
small: 'size-4',
|
|
13
|
+
medium: 'size-6',
|
|
14
|
+
large: 'size-8',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const checkboxIconSizeMapping: Record<CheckBoxSize, string> = {
|
|
18
|
+
small: 'size-3',
|
|
19
|
+
medium: 'size-5',
|
|
20
|
+
large: 'size-7',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type CheckboxProps = {
|
|
24
|
+
/** used for the label's `for` attribute */
|
|
25
|
+
id?: string,
|
|
26
|
+
label?: Omit<LabelProps, 'id'>,
|
|
27
|
+
/**
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
checked: CheckedState,
|
|
31
|
+
disabled?: boolean,
|
|
32
|
+
onChange?: (checked: boolean) => void,
|
|
33
|
+
onChangeTristate?: (checked: CheckedState) => void,
|
|
34
|
+
size?: CheckBoxSize,
|
|
35
|
+
className?: string,
|
|
36
|
+
containerClassName?: string,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A Tristate checkbox
|
|
41
|
+
*
|
|
42
|
+
* The state is managed by the parent
|
|
43
|
+
*/
|
|
44
|
+
const ControlledCheckbox = ({
|
|
45
|
+
id,
|
|
46
|
+
label,
|
|
47
|
+
checked,
|
|
48
|
+
disabled,
|
|
49
|
+
onChange,
|
|
50
|
+
onChangeTristate,
|
|
51
|
+
size = 'medium',
|
|
52
|
+
className = '',
|
|
53
|
+
containerClassName
|
|
54
|
+
}: CheckboxProps) => {
|
|
55
|
+
const usedSizeClass = checkboxSizeMapping[size]
|
|
56
|
+
const innerIconSize = checkboxIconSizeMapping[size]
|
|
57
|
+
|
|
58
|
+
const propagateChange = (checked: CheckedState) => {
|
|
59
|
+
if (onChangeTristate) {
|
|
60
|
+
onChangeTristate(checked)
|
|
61
|
+
}
|
|
62
|
+
if (onChange) {
|
|
63
|
+
onChange(checked === 'indeterminate' ? false : checked)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const changeValue = () => {
|
|
68
|
+
const newValue = checked === 'indeterminate' ? false : !checked
|
|
69
|
+
propagateChange(newValue)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<div className={clsx('row justify-center items-center', containerClassName)}>
|
|
74
|
+
<CheckboxPrimitive.Root
|
|
75
|
+
onCheckedChange={propagateChange}
|
|
76
|
+
checked={checked}
|
|
77
|
+
disabled={disabled}
|
|
78
|
+
id={id}
|
|
79
|
+
className={clsx(usedSizeClass, `items-center border-2 rounded outline-none focus:border-primary`, {
|
|
80
|
+
'text-disabled-text border-disabled-text': disabled,
|
|
81
|
+
'border-on-background': !disabled,
|
|
82
|
+
'bg-primary/30 border-primary text-primary': checked === true || checked === 'indeterminate',
|
|
83
|
+
'hover:border-gray-400 focus:hover:border-primary': !checked
|
|
84
|
+
}, className)}
|
|
85
|
+
>
|
|
86
|
+
<CheckboxPrimitive.Indicator>
|
|
87
|
+
{checked === true && <Check className={innerIconSize}/>}
|
|
88
|
+
{checked === 'indeterminate' && <Minus className={innerIconSize}/>}
|
|
89
|
+
</CheckboxPrimitive.Indicator>
|
|
90
|
+
</CheckboxPrimitive.Root>
|
|
91
|
+
{label &&
|
|
92
|
+
<Label {...label} className={clsx('cursor-pointer', label.className)} htmlFor={id} onClick={changeValue}/>}
|
|
93
|
+
</div>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
type UncontrolledCheckboxProps = Omit<CheckboxProps, 'value' | 'checked'> & {
|
|
98
|
+
/**
|
|
99
|
+
* @default false
|
|
100
|
+
*/
|
|
101
|
+
defaultValue?: CheckedState,
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A Tristate checkbox
|
|
106
|
+
*
|
|
107
|
+
* The state is managed by this component
|
|
108
|
+
*/
|
|
109
|
+
const UncontrolledCheckbox = ({
|
|
110
|
+
onChange,
|
|
111
|
+
onChangeTristate,
|
|
112
|
+
defaultValue = false,
|
|
113
|
+
...props
|
|
114
|
+
}: UncontrolledCheckboxProps) => {
|
|
115
|
+
const [checked, setChecked] = useState(defaultValue)
|
|
116
|
+
|
|
117
|
+
const handleChange = (checked: CheckedState) => {
|
|
118
|
+
if (onChangeTristate) {
|
|
119
|
+
onChangeTristate(checked)
|
|
120
|
+
}
|
|
121
|
+
if (onChange) {
|
|
122
|
+
onChange(checked === 'indeterminate' ? false : checked)
|
|
123
|
+
}
|
|
124
|
+
setChecked(checked)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<ControlledCheckbox
|
|
129
|
+
{...props}
|
|
130
|
+
checked={checked}
|
|
131
|
+
onChangeTristate={handleChange}
|
|
132
|
+
/>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export {
|
|
137
|
+
UncontrolledCheckbox,
|
|
138
|
+
ControlledCheckbox as Checkbox
|
|
139
|
+
}
|