cofi

cofi

  • Docs
  • Form Demos
  • Components Demos
  • Layout Demos
  • Editor
  • GitHub

›React Form

Getting started

  • Introduction

Form Class

  • Installation
  • Overview
  • Arguments
  • Id
  • Data
  • Fields
  • Path
  • Component
  • Formatter & Parser
  • Dependencies
  • Required
  • Validators
  • Exclude Term
  • Disable Term
  • Require Term
  • Dependencies Change
  • Context
  • Dirty
  • Invalid
  • Errors
  • Processing
  • Pending Actions
  • Hooks
  • Term
  • Log
  • Error Codes
  • Actions
  • Definition Shorthand

Advanced Usages

  • Grid Usage
  • Form Persistency
  • Undo & Redo
  • Replay Actions
  • Track Actions
  • Server Validation
  • Entity Templates
  • Folder Structure

React Form

  • Installation
  • Overview
  • Form
  • Field
  • Components
  • Layout
  • Demos

Tools

  • Editor
  • DevTools

More Info

  • Test Cofi
  • Packages
  • Why Cofi?
  • Technologies
  • Videos
  • Channels

Contribute

  • Code of Conduct
  • Contributing Guide
  • Contributors

Layout

Management layout react components of Item and List, to use in your app. With List component you can define a list page for any entity in your system. Item component is used to define editable / viewable pages, such as - create / edit / details entities pages - that render sections. Each section render a set of dynamic components.

In the demos we use Cofi's Form and Field components, but @cofi/react-layout packages does not depend on @cofi/react-form. Any other component can be used in the sections. A combination of both @cofi/react-form and @cofi/react-layout can create a complete solution for management pages.

Note: You can create different form page templates using the same form definition - but using different sections definition for each view / template. For example - for 'Video' entity you might want to show different layouts / fields for different users depending on their role / permissions in the system. See entity template usage.

Layout contains the following exposed components for usage:

Item Components

Item

React Component that render sections that contains dynamic components, as well as title, footer with actions, menu with actions and layout.

Import

import Item from '@cofi/react-layout/Item'

Props

NameTypeDescription
titlestringText that renders at the top of the Item
layoutstringRepresent the layout of the item. Can be one of scroll / tabs / mobile / undefined (default)
sectionsrequired arrayArray of objects. Each object can contain the data defined in Section and Section extend
mainActionsarrayRepresent the label of the action. Its required when layout is not mobile. Each object can contain the data defined in mainAction
optionsActionsarrayRepresent the label of the action. Its required when layout is not mobile. Each object can contain the data defined in optionAction
sizenumberRepresent layout size

Example

import Item from '@cofi/react-layout/Item';
import sections from './sections';

const item = {
  title: 'Employee',
  layout: 'scroll',
  size: 2,
  sections,
  mainActions: [{
    label: 'Cancel',
    type: 'tertiary',
    onClick: () => {},
  }, {
    label: 'Save & Close',
    type: 'secondary',
    disable: () => true,
    onClick: () => {},
  }, {
    label: 'Save',
    type: 'primary',
    icon: SaveIcon,
    disable: () => true,
    onClick: () => {}
    popover: {
      title: 'Handle Fields',
      open: () => true,
      component: props => `Save alert: ${props.message}`,
      props: { 
        message: 'Please fix invalid fields',
      },
    },
  }],
  optionsActions: [{
    label: 'Archive',
    onClick: () => {},
  }, {
    label: 'History',
    onClick: () => {},
    exclude: () => false,
  }, {
    label: 'Report To HR',
    onClick: () => {},
    disable: () => false,
  }, {
    label: 'Delete',
    onClick: () => {},
  }],
};

<Item {...item} />

sections.js - Using css grid example:

import { Field } from '@cofi/react-form';

const getGrid = (templateAreas) => {
  let fieldIds = templateAreas.join(' ').split(' ').filter(x => x !== '.');
  fieldIds = [...(new Set(fieldIds))];
  return {
    templateAreas,
    templateColumns: 'repeat(3, minmax(0, 1fr))',
    elements: fieldIds.map(id => ({ 
      selector: `#${id}`, 
      gridArea: id, 
      component: Field, 
      props: { id },
      style: 'width: 350px;',
    })),
  };
};

export default [{
  id: 'personal-information',
  title: 'Personal Information',
  grid: getGrid([
    'firstName lastName .',
    'personalId address .',
  ]),
}, {
  id: 'job-information',
  title: 'Job Information',
  grid: getGrid([
    'department level .',
    'benefits . .',
  ]),
}, {
  id: 'raw-data',
  title: 'Raw Data',
  grid: getGrid([
    'id creationDate .',
    'modifier modificationDate .',
  ]),
  sections: [{
    id: 'raw-data-general',
    title: 'General',
    grid: getGrid([
      'id modifier .',
    ]),
  }, {
    id: 'raw-data-modification',
    title: 'Modification',
    grid: getGrid([
      'creationDate modificationDate .',
    ]),
  }],
}];

sections.js - Using boxes example:

import { Field } from '@cofi/react-form';

const column = (fieldIds) => ({
  style: `
    display: flex;
    flex-direction: column;
    width: 400px;
    max-width: 400px;
    margin: 0 30px 0 0;

    [aria-label="Field"] {
      margin: 0 20px 20px 0;
    }
  `,
  boxes: fieldIds.map(id => ({ component: Field, props: { id } })),
});

const row = (columns) => ({
  style: {
    display: 'flex',
    flexDirection: 'row',
  },
  boxes: columns.map(fieldIds => column(fieldIds)),
});

export default [{
  id: 'personal-information',
  title: 'Personal Information',
  boxes: [row([
    ['firstName', 'lastName'],
    ['personalId', 'address'],
  ])],
}, {
  id: 'job-information',
  title: 'Job Information',
  boxes: [row([
    ['department', 'benefits'],
    ['level'],
  ])],
}, {
  id: 'raw-data',
  title: 'Raw Data',
  boxes: [row([
    ['id', 'modifier'],
    ['creationDate', 'modificationDate'],
  ])],
  sections: [{
    id: 'raw-data-general',
    title: 'General',
    boxes: [row([
      ['id'],
      ['modifier'],
    ])],
  }, {
    id: 'raw-data-modification',
    title: 'Modification',
    boxes: [row([
      ['creationDate'],
      ['modificationDate'],
    ])],
  }],
}];

section extend

NameTypeDescription
excludefunctionCallback function that is evaluated on render and should return true if currently the section should be excluded

mainAction

NameTypeDescription
labelstringRepresent the label of the action. Its required when layout is not mobile
iconfunctionReact component that renders svg icon. Its required when layout is mobile
typestringRepresent the type of the action. Can be one of primary (default) / secondary / tertiary
onClickfunctionCallback function that is called when user triggers the action
disablefunctionCallback function that is evaluated on render and should return true if currently the action should be disabled
excludefunctionCallback function that is evaluated on render and should return true if currently the action should be excluded
popoverobjectRepresent popover that appears above the action. Relevant for non mobile layouts. Contains data defined in popover

optionAction

NameTypeDescription
labelrequired stringRepresent the label of the action
onClickfunctionCallback function that is called when user triggers the action
disablefunctionCallback function that is evaluated on render and should return true if currently the action should be disabled
excludefunctionCallback function that is evaluated on render and should return true if currently the action should be excluded

popover

NameTypeDescription
titlestringRepresent the title of the popover
openfunctionCallback function that is evaluated on render and should return true if currently the popover should be open
componentfunctionReact component to be rendered in the popover body
propsobjectProps object to be passes to the body's component

Section

React Component that renders title and composition of components. Each composition of components can be defined using boxes configuration or css grid configuration. Each section can contain sub sections as well.

Import

import Section from '@cofi/react-layout/Section'

Props

NameTypeDescription
idrequired stringId of the section
titlestringTitle the section
gridobjectObject contain the data defined in Grid
boxesobject arrayEach object can contain the data defined in Box
sectionsobject arraySub sections, each object can contain the data defined in Section
sizenumberRepresent section size

Grid

Component represent css grid.

Import

import Grid from '@cofi/react-layout/Grid'

Props

NameTypeDescription
elementsrequired object arrayEach object contains selector, gridArea, component, props, style
templateAreasrequired string arrayRepresent grid-template-areas property in css grid
templateColumnsstringRepresent grid-template-columns property in css grid
gapstringRepresent grid-gap property in css grid

Box

Box can be either styled box (by defining style object or styled string, boxes array) or a dynamic component (by defining component and props).

Import

import Box from '@cofi/react-layout/Box'

Props

NameTypeDescription
styleobject / stringStyle of the box element
boxesarraySub boxes
componentfunctionDynamic react component to be rendered
propsobjectProps to pass to the rendered component

List Components

TBD - React Component that render grid and filters components.

← ComponentsDemos →
  • Item Components
    • Item
    • Section
    • Grid
    • Box
  • List Components
cofi
Copyright © 2021 Verizon Media
DOCS
IntroductionForm ClassReact FormReact ComponentsReact Layout
DEMOS
React FormReact ComponentsReact Layout
CONTRIBUTING
Code Of ConductContributing GuideContributorsUsers
CHANNELS
StarGitHubStack OverflowMediumVideos