@gechiui/components
Version:
UI components for GeChiUI.
172 lines (122 loc) • 3.66 kB
Markdown
<div class="callout callout-alert">
This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes.
</div>
BoxControl components let users set values for Top, Right, Bottom, and Left. This can be used as an input control for values like `padding` or `margin`.
```jsx
import { __experimentalBoxControl as BoxControl } from '@gechiui/components';
import { useState } from '@gechiui/element';
const Example = () => {
const [ values, setValues ] = useState( {
top: '50px',
left: '10%',
right: '10%',
bottom: '50px',
} );
return (
<BoxControl
values={ values }
onChange={ ( nextValues ) => setValues( nextValues ) }
/>
);
};
```
BoxControl provides a companion component that visually renders value changes. Place the component you would like the sides visualized within the companion `<Visualizer>` component.
```jsx
import { __experimentalBoxControl as BoxControl } from '@gechiui/components';
import { useState } from '@gechiui/element';
import MyComponent from './my-component';
const { Visualizer } = BoxControl;
const Example = () => {
const [ values, setValues ] = useState( {
top: '50px',
left: '10%',
right: '10%',
bottom: '50px',
} );
return (
<>
<BoxControl
values={ values }
onChange={ ( nextValues ) => setValues( nextValues ) }
/>
<Visualizer>
<MyComponent />
</Visualizer>
</>
);
};
```
Alternatively, the `<Visualizer>` can be nested as a sibling to the component you would like visualized. Using `<Visualizer />` in this manner will require the parent element having a `position` style.
```jsx
import { __experimentalBoxControl as BoxControl } from '@gechiui/components';
import { useState } from '@gechiui/element';
import MyComponent from './my-component';
const { Visualizer } = BoxControl;
const Example = () => {
const [ values, setValues ] = useState( {
top: '50px',
left: '10%',
right: '10%',
bottom: '50px',
} );
return (
<>
<BoxControl
values={ values }
onChange={ ( nextValues ) => setValues( nextValues ) }
/>
<div style={ { position: 'relative' } }>
<Visualizer />
<MyComponent />
</div>
</>
);
};
```
If this property is true, a button to reset the box control is rendered.
- Type: `Boolean`
- Required: No
- Default: `true`
If this property is true, when the box control is unlinked, vertical and horizontal controls can be used instead of updating individual sides.
- Type: `Boolean`
- Required: No
- Default: `false`
Props for the internal [InputControl](../input-control) components.
- Type: `Object`
- Required: No
Heading label for BoxControl.
- Type: `String`
- Required: No
- Default: `Box Control`
A callback function when an input value changes.
- Type: `Function`
- Required: Yes
A callback function for visualizer changes, based on input hover interactions.
- Type: `Function`
- Required: Yes
The `top`, `right`, `bottom`, and `left` box dimension values to use when the control is reset.
- Type: `Object`
- Required: No
Collection of sides to allow control of. If omitted or empty, all sides will be available.
- Type: `Array<Object>`
- Required: No
Collection of available units which are compatible with [UnitControl](../unit-control).
- Type: `Array<Object>`
- Required: No
The `top`, `right`, `bottom`, and `left` box dimension values.
- Type: `Object`
- Required: No