Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sagold committed Dec 22, 2024
1 parent 43532c2 commit e6d5ee4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
8 changes: 6 additions & 2 deletions packages/rje-mantine-widgets/src/docs/Widgets.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ const schema: JsonSchema = {
string: {
type: 'string',
title: 'string',
description: 'standard mantine **TextInput**',
description: 'standard mantine text **Input**',
maxLength: 10,
options: {
clearable: true,
icon: 'gesture',
tag: '👍'
}
Expand All @@ -115,7 +116,7 @@ const schema: JsonSchema = {
title: 'time',
type: 'string',
format: 'time',
description: 'mantine time input',
description: 'mantine **TimeInput**',
minLength: 1
},
date: {
Expand Down Expand Up @@ -212,6 +213,9 @@ const schema: JsonSchema = {
description: 'standard mantine multi-select',
type: 'array',
uniqueItems: true,
options: {
liveUpdate: true
},
items: {
type: 'string',
enum: ['yes', 'maybe', 'no']
Expand Down
16 changes: 3 additions & 13 deletions packages/rje-mantine-widgets/src/widgets/useLiveUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,19 @@ export function useLiveUpdate<T = unknown>(
* ------------------------------*/
// track current state and expose value to input
const [state, setState] = useState(currentValue);
const onChange = useCallback(
(event) => {
setState(retrieveValue(event) as T);
},
[setState, retrieveValue]
);
const onChange = useCallback((event) => setState(retrieveValue(event) as T), [setState, retrieveValue]);

// track initial value for changes and update internal state accordingly
const [previousValue, setPreviousValue] = useState(currentValue);
if (!deepEqual(previousValue, currentValue)) {
setState(currentValue);
setPreviousValue(currentValue);
setState(currentValue);
}

/* --------------------------------
* update on change (live)
* ------------------------------*/
const onLiveChange = useCallback(
(event) => {
setValue(retrieveValue(event) as T);
},
[setValue, retrieveValue]
);
const onLiveChange = useCallback((event) => setValue(retrieveValue(event) as T), [setValue, retrieveValue]);
if (liveUpdate === true) {
return { value: currentValue, onChange: onLiveChange };
}
Expand Down

0 comments on commit e6d5ee4

Please sign in to comment.