0.18.0 • Published 5 years ago

@pndr/record-gallery-card v0.18.0

Weekly downloads
11
License
MIT
Repository
-
Last release
5 years ago

RecordGalleryCard

npm package

Used for displaying a record as a gallery card.

RecordGalleryCard

Getting started

npm install @cmds/record-gallery-card --save

Prop Types

PropertyTypeRequired?Description
idStringUnique id for the instance of this record
nameStringName for the record
coverAttachmentsArrayEach attachment be displayed in a the card's cover as a carousel
coverFitTypeIdCoverFitTypeEither crop or fit. The images inside the cover will be either covered or contained, respectively
coverEnabledBooleanWhether the cover should be displayed or not
fieldsArrayList of field objects containing the name and more information for each field.
visibleFieldOrderArrayA list of ids for the fields that need to be displayed and in which order
fieldHeightGetterFunctionResponsible for returning the height for the field: ({field: object}): number
fieldRendererFunctionResponsible for rendering a field given it's configuration: ({recordId: string, index: number, field: object}): jsx Learn more
onClickFunctionTriggers when the user clicks the record gallery card: ({id: string, e: ClickEvent})

fieldRenderer

Responsible for rendering a field given it's configuration.

import SingleLineTextField from '@cmds/single-line-text-field'
// import all other fields that need to be supported...

const renderers = {
    singleLineText: ({props}) => (
        <SingleLineTextField
            {...props}
            text={'Luke Skywalker'}
            onChange={({id, text}) => {
                
                // store new value
            }}
        />
    ),
    // and all other fields that need to be supported
}

function fieldRenderer({id, index, field, props}) {

    const renderer = renderers[field.typeId]
    
    if (!renderer) {
        throw new Error(`Renderer for typeId '${field.typeId}' not found`)
    }
    
    /**
     * Note — props already contains properties
     * related to the context in which the field
     * gets rendered.
     * 
     * {
     *      id: 'fld1', // the field's id
     *      contextId: 'recordGalleryCard',
     *      roleId: 'readOnly'
     * }
     */
    
    return renderer({ 
        id, 
        field,
        props
    })
}

More information

This component is designed and developed as part of Cosmos Design System.

0.18.0

5 years ago

0.17.0

5 years ago

0.16.0

5 years ago

0.15.0

5 years ago

0.14.0

5 years ago

0.13.0

5 years ago

0.12.0

5 years ago

0.11.0

5 years ago

0.10.0

5 years ago

0.9.0

5 years ago