useButtonGroupField
Reads the value of a button-group field.
function useButtonGroupField(props: {field: string; defaultValue?: string}): string | null
Arguments
| Property | Type | Description |
|---|---|---|
| field | string | The name of the field. |
| defaultValue | string | The value returned while no button is selected. |
Returns
The value of the selected button. If no button is selected, the defaultValue, or null without a defaultValue.
Pass the same defaultValue as in the mobro-widget-config.json. The dashboard builder shows the button of the
defaultValue as selected after users cleared the field, and the widget should behave accordingly.
Example
src/widgets/example/Example.tsx
import React from 'react'
import {useButtonGroupField} from '@modbros/dashboard-sdk'
export default function Example() {
const textAlign = useButtonGroupField({field: 'text_align', defaultValue: 'left'})
return <div style={{textAlign: textAlign as React.CSSProperties['textAlign']}}>Aligned text</div>
}
Setter
useSetButtonGroupField({field}) returns a setter to change the selected button from within the widget, see
Setter Hooks.