# UI components Strapi provides built-in UI Components to make development faster. ## Button Button library based on bootstrap classes. {% center %} ![Buttons img](../assets/buttons.png) {% endcenter %} ### Usage | Property | Type | Required | Description | | -------- | ---- | -------- | ----------- | | `children`| node | no | Ex: `` | | `className` | any | no | Sets a custom className. Ex: `` | | `secondary`| bool | no | [Bootstrap className](https://v4-alpha.getbootstrap.com/components/buttons/) | | `secondaryHotline` | bool | no | Sets className | | `secondaryHotlineAdd` | bool | no | Inserts fontAwesone plus icon inside the button. Ex: `` | | `type` | string | no | Sets the button type | ### Example **Path —** `./plugins/my-plugin/admin/src/translations/en.json`. ```json { "myPlugin.button.label": "Add a new" } ``` **Path —** `./plugins/my-plugin/admin/src/components/Foo/index.js`. ```js // Make sure you don't have any other component called Button otherwise it will // import the one from your ./components folder instead. import Button from 'components/Button'; const Foo = () => { // Define your buttons const buttons = [ { kind: 'primaryAddShape', label: 'myPlugin.button.label', labelValues: { foo: 'Bar', }, onClick: () => console.log('Click'), }, ]; return (
{buttons.map((buttonProps) =>
); } // Will display a primaryAddShape button with label: 'Add a new Bar' export default Button; ``` *** ## Input Strapi provides a built-in input library which includes : - All kind of inputs - Front-End validations - Error highlight - i18n ### Usage | Property | Type | Required | Description | | -------- | ---- | -------- | ----------- | | `addon` | string | no | Allows to add a string addon in your input, based on [Bootstrap](https://v4-alpha.getbootstrap.com/components/input-group/#basic-example). Ex: `` | | `addRequiredInputDesign` | bool | no | Allows to add an asterix on the input. Ex: `` | | `customBootstrapClass` | string | no | Allows to override the input bootstrap col system. Ex: `` | | `deactivateErrorHighlight` | bool | no | Prevents from displaying error highlight in the input: Ex: `` | | `didCheckErrors` | bool | no | Use this props to display errors after submitting a form. Ex: `` | | `disabled` | bool | no | Disable the input. Ex: `` | | `errors` | array | no | Allows to display custom error messages. Ex: `` | | `handleBlur` | func or bool | no | Overrides the default onBlur behavior. If bool passed to the component it will disabled the input validations checking. | | `handleChange` | func | yes | Sets your reducer state. | | `handFocus` | func | no | Adds an onFocus event to the input. | | `inputDescription` | string | no | Allows to add an input description that is displayed like [bootstrap](https://v4-alpha.getbootstrap.com/components/forms/#defining-states). | | `label` | string | yes | Displays the input's label with i18n. | | `linkContent` | object | no | Allows to display a link within the input's description. Ex: {% raw %} ``` ``` {% endraw %} | | `name` | string | yes | The key to update your reducer. | | `noErrorsDescription` | bool | no | Prevents from displaying built-in errors. | | `placeholder` | string | no | Allows to set a placeholder. | | `pluginId` | string | no | Use to display name, placeholder, etc. with i18n. | | `selectOptions` | array | no | Options for the select. | | `tabIndex` | string | no | Sets the order in which the inputs are focused on tab key press. | | `title` | string | no | This props can only be used for checkboxes, it allows to add a title on top of the input, the label will be on the right side of the checkbox. | | `validations` | object | yes | Allows to have the built-in input's validations. If set to {} the validations will be ignored. Ex: {% raw %} ``` ``` {% endraw %} | | `value` | string or bool or number | yes | The input's value. | ### Example ```js import React from 'react'; // Make sure you don't have a component called Input inside your ./components folder // It will import the one in your components folder instead. import Input from 'components/Input'; class FooPage extends React.Component { constructor(props) { super(props); this.state { data: { foo: 'bar', }, error: false, errors: [], }; } handleChange = ({ target }) => { const value = target.type === 'number' ? Number(target.value) : target.value; const error = target.value.length === 0; if (error) { this.setState({ error: true, errors: [{ id: 'This input is required ' }] }); } else { this.setState({ data[target.name]: value, error: false, errors: [] }); } } render() { return (
); } } export default FooPage; ``` *** ## PopUp Warning PopUp warning library based on [reactstrap](https://reactstrap.github.io/components/modals/). {% center %} ![PopUp warning img](../assets/popup-warning.png) {% endcenter %} ### Usage | Property | Type | Required | Description | | -------- | ---- | -------- | ----------- | | bodyMessage | string | no | Body message of the pop up (works with i18n). | | handleConfirm | func | yes | Function executed when the user clicks on the `Confirm button`. | | isOpen | bool | yes | Show or hide the popup. | | popUpWarningType | string | yes | Sets the popup body icon. Available types: `danger`, `info`, `notFound`, `success`, `warning` | | toggleModal | func | yes | Function to toggle the modal. | ### Example **Path —** `./plugins/my-plugin/admin/src/translations/en.json`. ```json { "button.label": "Click me", "popup.danger.message": "Are you sure you want to delete this item?" } ``` **Path —** `./plugins/my-plugin/admin/src/translations/fr.json`. ```json { "button.label": "Cliquez", "popup.danger.message": "Êtes-vous certain de vouloir supprimer ce message?" } ``` **Path —** `./plugins/my-plugin/admin/src/containers/FooPage/index.js`. ```js // ... import Button from 'components/Button'; import PopUpWarning from 'components/PopUpWarning'; // ... class FooPage extends React.Component { constructor(props) { super(props); this.state = { isOpen: false, }; } handlePopUpConfirm = () => { // Some logic Here this.setState({ isOpen: false }); } render() { return(
); } } export default FooPage; ```