diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index 06d246c01a..b94e96c7de 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -9,6 +9,7 @@ import InterfaceDropdown from './dropdown/'; import InterfaceDropdownMultiselect from './dropdown-multiselect/'; import InterfaceRadioButtons from './radio-buttons'; import InterfaceCheckboxes from './checkboxes'; +import InterfaceStatus from './status'; export const interfaces = [ InterfaceTextInput, @@ -22,6 +23,7 @@ export const interfaces = [ InterfaceDropdownMultiselect, InterfaceRadioButtons, InterfaceCheckboxes, + InterfaceStatus, ]; export default interfaces; diff --git a/src/interfaces/status/index.ts b/src/interfaces/status/index.ts new file mode 100644 index 0000000000..ae52f77502 --- /dev/null +++ b/src/interfaces/status/index.ts @@ -0,0 +1,17 @@ +import InterfaceStatus from './status.vue'; +import { defineInterface } from '@/interfaces/define'; + +export default defineInterface(({ i18n }) => ({ + id: 'status', + name: i18n.t('status'), + icon: 'bubble_chart', + component: InterfaceStatus, + options: [ + { + field: 'status_mapping', + name: i18n.t('status_mapping'), + width: 'full', + interface: 'code', + }, + ], +})); diff --git a/src/interfaces/status/readme.md b/src/interfaces/status/readme.md new file mode 100644 index 0000000000..93246c30ca --- /dev/null +++ b/src/interfaces/status/readme.md @@ -0,0 +1,26 @@ +# Status Interface + +Renders a dropdown with the available status options. + +## Options + +| Option | Description | Default | +|------------------|-----------------------------|---------| +| `status_mapping` | What statuses are available | `null` | + +### Status Mapping format + +```ts +type Status = { + [key: string]: { + name: string; + text_color: string; + background_color: string; + soft_delete: boolean; + published: boolean; + } +} +``` + +`status_mapping` is the only option for an interface that isn't camelCased. This is due to the fact +that the API relies on the same setting for it's permissions management. diff --git a/src/interfaces/status/status.story.ts b/src/interfaces/status/status.story.ts new file mode 100644 index 0000000000..c5d96f2b9f --- /dev/null +++ b/src/interfaces/status/status.story.ts @@ -0,0 +1,55 @@ +import withPadding from '../../../.storybook/decorators/with-padding'; +import { defineComponent, ref } from '@vue/composition-api'; +import { boolean, withKnobs, object } from '@storybook/addon-knobs'; +import readme from './readme.md'; +import RawValue from '../../../.storybook/raw-value.vue'; +import i18n from '@/lang'; + +export default { + title: 'Interfaces / Status', + decorators: [withPadding, withKnobs], + parameters: { + notes: readme, + }, +}; + +export const basic = () => + defineComponent({ + i18n, + components: { RawValue }, + props: { + statusMapping: { + default: object('Status Mapping', { + published: { + name: 'Published', + background_color: 'var(--primary)', + }, + draft: { + name: 'Draft', + background_color: 'var(--background-normal)', + }, + deleted: { + name: 'Deleted', + background_color: 'var(--danger)', + }, + }), + }, + disabled: { + default: boolean('Disabled', false), + }, + }, + setup() { + const value = ref(null); + return { value }; + }, + template: ` +