-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(forms): refactor and add "Getting started" to its own page
- Loading branch information
1 parent
ee5014f
commit 8c311d8
Showing
14 changed files
with
344 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...n-system-portal/src/docs/uilib/extensions/forms/create-component/FieldBlock.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...system-portal/src/docs/uilib/extensions/forms/create-component/useDataValue.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: 'useDataValue' | ||
description: 'The `useDataValue` hook standardize handling of the value flow for a single consumer component representing one data point.' | ||
componentType: 'basis-api' | ||
hideInMenu: true | ||
showTabs: true | ||
tabs: | ||
- title: Info | ||
key: '/info' | ||
- title: Demos | ||
key: '/demos' | ||
breadcrumb: | ||
- text: Forms | ||
href: /uilib/extensions/forms/ | ||
- text: Create your component | ||
href: /uilib/extensions/forms/create-component/ | ||
- text: useDataValue | ||
href: /uilib/extensions/forms/create-component/useDataValue/ | ||
--- | ||
|
||
import Info from 'Docs/uilib/extensions/forms/create-component/useDataValue/info' | ||
import Demos from 'Docs/uilib/extensions/forms/create-component/useDataValue/demos' | ||
|
||
<Info /> | ||
<Demos /> |
111 changes: 111 additions & 0 deletions
111
...-system-portal/src/docs/uilib/extensions/forms/create-component/useDataValue/Examples.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import React from 'react' | ||
import ComponentBox from '../../../../../../shared/tags/ComponentBox' | ||
import { | ||
Field, | ||
FieldBlock, | ||
Form, | ||
JSONSchema, | ||
useDataValue, | ||
} from '@dnb/eufemia/src/extensions/forms' | ||
import { Flex, Slider } from '@dnb/eufemia/src' | ||
|
||
export const CustomComponentExample = () => { | ||
return ( | ||
<ComponentBox scope={{ useDataValue, FieldBlock }}> | ||
{() => { | ||
const MySliderComponent = (props) => { | ||
const fromInput = React.useCallback( | ||
(event) => | ||
typeof event === 'number' ? event : event?.value || 0, | ||
[], | ||
) | ||
|
||
const errorMessages = React.useMemo( | ||
() => ({ | ||
required: 'This field is required', | ||
...props.errorMessages, | ||
}), | ||
[props.errorMessages], | ||
) | ||
const schema = React.useMemo<JSONSchema>( | ||
() => | ||
props.schema ?? { | ||
type: 'number', | ||
minimum: props.minimum, | ||
maximum: props.maximum, | ||
}, | ||
[props.schema, props.minimum, props.maximum], | ||
) | ||
|
||
const preparedProps = { | ||
fromInput, | ||
schema, | ||
...errorMessages, | ||
label: 'Label', | ||
...props, | ||
} | ||
|
||
const { | ||
id, | ||
label, | ||
info, | ||
warning, | ||
error, | ||
value, | ||
width = 'medium', | ||
minimum = 0, | ||
maximum = 100, | ||
step = 1, | ||
handleChange, | ||
handleFocus, | ||
handleBlur, | ||
} = useDataValue(preparedProps) | ||
|
||
const steps = { minimum, maximum, step } | ||
|
||
return ( | ||
<FieldBlock | ||
forId={id} | ||
label={label} | ||
info={info} | ||
warning={warning} | ||
error={error} | ||
width={width} | ||
> | ||
<Flex.Stack> | ||
<Field.Number | ||
value={value} | ||
showStepControls | ||
onChange={handleChange} | ||
onFocus={handleFocus} | ||
onBlur={handleBlur} | ||
{...steps} | ||
/> | ||
<Slider | ||
id={id} | ||
value={value} | ||
onChange={handleChange} | ||
onDragStart={handleFocus} | ||
onDragEnd={handleBlur} | ||
{...steps} | ||
/> | ||
</Flex.Stack> | ||
</FieldBlock> | ||
) | ||
} | ||
|
||
return ( | ||
<Form.Handler data={{ sliderValue: 50 }}> | ||
<MySliderComponent | ||
path="/sliderValue" | ||
minimum={50} | ||
maximum={80} | ||
required | ||
info="Info" | ||
/> | ||
</Form.Handler> | ||
) | ||
}} | ||
</ComponentBox> | ||
) | ||
} |
23 changes: 23 additions & 0 deletions
23
...-portal/src/docs/uilib/extensions/forms/create-component/useDataValue/demos.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
showTabs: true | ||
--- | ||
|
||
import * as Examples from './Examples' | ||
|
||
## Demos | ||
|
||
On the consumer side, we can use this custom component like so: | ||
|
||
```jsx | ||
<Form.Handler data={{ sliderValue: 50 }}> | ||
<MySliderComponent | ||
path="/sliderValue" | ||
minimum={50} | ||
maximum={80} | ||
required | ||
info="Info" | ||
/> | ||
</Form.Handler> | ||
``` | ||
|
||
<Examples.CustomComponentExample /> |
Oops, something went wrong.