cm-react-components
Repository for shared React components build atop of Origami and maintained by the C&M team
Contents
Button
Header
(withNavigation
andClientNavigation
inside)Layout
Footer
Installation
In order to install cm-react-components you can run one of the following commands on the package.json
's level inside your React project.
npm install --save git+https://github.com/Financial-Times/cm-react-components.git
or
yarn add git+https://github.com/Financial-Times/cm-react-components.git
Usage
These shared components should be named imports, e.g:
import { Button } from 'cm-react-components'
inside the file your want to use this component.
Every component has variation of props
which can be passed to it, some of them for visual purposes and some of them for functional:
Button
id
(string) - id which would be attached to the DOMbutton
elementdisabled
(boolean) - if this props is passed, thebutton
would be disabled and it cannot be clickedonClick
(function) - a callback function which would handle the click of thebutton
title
(string) - title which would be attached to the DOMbutton
elementclassName
(string) - an additional class name can be passed from the parent and styles of this class would be applied to thebutton
primary
(boolean) - this is an origami prop which would appendorigami's primary classname
to the buttonsecondary
(boolean) - this is an origami prop which would appendorigami's secondary classname
to the buttoninverse
(boolean) - this is an origami prop which would appendorigami's inverse classname
to the buttonbig
(boolean) - this is an origami prop which would appendorigami's big classname
to the buttonmono
(boolean) - this is an origami prop which would appendorigami's mono classname
to the buttonb2c
(boolean) - this is an origami prop which would appendorigami's b2c classname
to the buttonchildren
(string/node) -children
could be passed to the button in order to fill the content inside iticon
(string) - this is an origami prop which would appendorigami's icon classname
to the button. If nochildren
prop is passed, it would also appendicon-only
classname (see link below for all available icons)
For more information about Origami's button class names visit the official documentation of Origami buttons components.
-
Header
The header is a component which contains alsoNavigation
andClientNavigation
components.Header
should be wrapped around<BrowserRouter>
, otherwise it would not work.-
renderProp
(function) - a function which should return the Child component inside everyli
of theNavigation
, e.g:NavLink
orLink
fromreact-router-dom
orLink
fromgatsby-link
-
title
(string) - the title of the application for example which would be rendered inside theheader
-
name
(string) - If we have secondary navigation (ClientNavigation
) this is used for visualizing the name of the client/user which uses the secondary navigation. This prop goes with the next oneid
-
id
(string) - If we have secondary navigation (ClientNavigation
) this is used for navigating to the different client routes with thisid
. Used with the previous propname
-
mainMenuData
(array) - an array of objects which contains the different application routes for the main navigation (MainNavigation
), e.g.:[ { label: 'Main route label', url: '/main-route' }, { label: 'Main route label 2', url: '/main-route-2' } ];
-
secondaryMenuData
(array) - an array of objects which contains the different application routes for the secondary navigation (SecondaryNavigation
), e.g.:[ { label: 'Secondary route label', url: '/secondary-route' }, { label: 'Secondary route label 2', url: '/secondary-route-2' } ];
-
clientMenuData
(array) - an array of objects which contains the different application routes for the client navigation (ClientNavigation
), e.g.:[ { label: 'Client route label', url: '/client-route' }, { label: 'Client route label 2', url: '/client-route-2' } ];
-
-
Layout
children
(string/node) - the components rendered inside theLayout
-
Layout.Main
children
(string/node) - the components rendered inside theLayout.Main
-
Footer
-
link
(array) - an array of objects which contain the different links rendered inside thefooter
, e.g:[ { link: 'http://link-number-1.com/', text: 'Text for link #1' }, { label: 'http://link-number-2.com/', text: 'Text for link #2' } ];
-
-
CheckInput
isToggle
(boolean) - if this prop is passed the origami's checkbox is rendered as a toggle buttonclassName
(string) - an additional class name can be passed from the parent and styles of this class would be applied to the checkboxsmall
(boolean) - this is an origami prop which would appendorigami's small classname
to the checkboxdisabled
(boolean) - if this prop is passed, the checkbox would be disabled and it cannot be checked/uncheckedchecked
(boolean) - a prop which indicates the value of the checkbox - checked/uncheckedonChange
(function) - a callback function which would handle the change of the checkboxlabel
(string) - a label which would be rendered next to the checkbox
For more information about Origami's checkbox class names visit the official documentation of Origami checkbox components.
FormsField
children
(string/node) -children
passed to theFormsField
in order to render a form field inside the wrappercontainerTag
(string) - One oflabel
ordiv
- the wrapper tag used forFormsField
componenttitle
(string) - if it is passed a title withtitlePromp
andtitleProps
is rendered before the form fieldtitlePrompt
(string/node) - additional text rendered under thetitle
- in order the prompt to be rendered,title
should be passedtitleProps
(object) - additional title props which could be passed for the title (verticalCenter
,shrink
)className
(string) - an additional class name can be passed from the parent and styles of this class would be applied to theFormsField
inline
(boolean) - this is an origami prop which would appendorigami's inline classname
to theFormsField
optional
(boolean) - this is an origami prop which would appendorigami's optional classname
to theFormsField
inverse
(boolean) - this is an origami prop which would appendorigami's inverse classname
to theFormsField
For more information about Origami's additional class names visit the official documentation of Origami forms components.
RadioInput
-
className
(string) - an additional class name can be passed from the parent and styles of this class would be applied to theRadioInput
-
small
(boolean) - this is an origami prop which would appendorigami's small classname
to theRadioInput
-
inline
(boolean) - this is an origami prop which would appendorigami's inline classname
to theRadioInput
-
disabled
(boolean) - if this prop is passed, theRadioInput
would be disabled and it cannot be checked/unchecked -
isRounded
(boolean) - if this prop is passed the origami'sRadioInput
is rendered rounded -
options
(array) - an array of objects with different options for the radio button, e.g:[ { name: 'Option 1', value: 'option1' }, { label: 'Option 2', url: 'option2' } ];
-
name
(string) - a name attribute of the radio inputs -
onChange
(function) - a callback function which would handle the change of theRadioInput
-
selectedValue
(string) - the current selected value of all options
-
For more information about Origami's radio input class names visit the official documentation of Origami forms components.
SelectBox
-
className
(string) - an additional class name can be passed from the parent and styles of this class would be applied to theSelectBox
-
small
(boolean) - this is an origami prop which would appendorigami's small classname
to theSelectBox
-
hasError
(boolean) - indicates if theSelectBox
has an error and shows theerrorMessage
-
errorMessage
(string) - ifhasError
is true, then this message is shown -
primary
(boolean) - this is an origami prop which would appendorigami's primary classname
to theSelectBox
-
isTouched
(boolean) - indicates if theSelectBox
has been touched or not -
disabled
(boolean) - if this prop is passed, theSelectBox
would be disabled and it options cannot be selected -
selectedValue
(string) - the current selected value of all options -
onChange
(function) - a callback function which would handle the change of theSelectBox
-
placeholderOptions
(object) - object which contains the placeholder's value and name, which are needed a option as a placeholder to be rendered -
options
(array) - an array of objects containing the options which are rendered inside theSelectBox
, e.g.:[ { name: 'Option 1', value: 'option1', id: 'id1', type: 'type1', disabled: true }, { name: 'Option 2', value: 'option2', id: 'id2', type: 'type2', disabled: false } ];
-
For more information about Origami's select box class names visit the official documentation of Origami forms components.
TextInput
className
(string) - an additional class name can be passed from the parent and styles of this class would be applied to theTextInput
small
(boolean) - this is an origami prop which would appendorigami's small classname
to theTextInput
disabled
(boolean) - if this prop is passed, theTextInput
would be disabled and it cannot be checked/uncheckedinputType
(string) - the type of the input (default value istext
), one oftext
,password
,email
,number
,textarea
onChange
(function) - a callback function which would handle the change of theTextInput
onChange
(function) - a callback function which would handle the blur of theTextInput
onBlur
(function) - a callback function which would handle thekeyDown event
of theTextInput
hasError
(boolean) - indicates if theTextInput
has an error and shows theerrorMessage
errorMessage
(string) - ifhasError
is true, then this message is shownisTouched
(boolean) - indicates if theTextInput
has been touched or notrows
- (number) - the rows count in case theinputType
istextarea
(defaults to 4)
For more information about Origami's text input/area class names visit the official documentation of Origami forms components.
Tooltip
useTooltip
hook should be imported as well
-
Tooltip
should be used with parent container with classwith-tooltip
andparentContainerRef
should be passed touseTooltip
hook in order to be correctly vertical positioned, e.g:<div ref={parentContainerRef} className="with-tooltip"> <button ref={elementRef} onClick={clickHandler}>Tooltip</Button> <Tooltip /> </div>
-
elementRef
(see example above) should be passed touseTooltip
hook in order Tooltip to be correctly horizontal positioned -
If the "tooltiped" element (
button
in the example above) is a react component then it should be transformed to forwardRef (see Button.jsx)
-
Tooltip
propsisVisible
(bool) - indicates ifTooltip
is visible or not (returned fromuseTooltip
)top
(number) - top position of theTooltip
(returned fromuseTooltip
)left
(number) - left position of theTooltip
(returned fromuseTooltip
)children
(string/node) - content rendered inside the Tooltipclose
(function) - a callback used for closing theTooltip
(returned fromuseTooltip
)
-
useTooltip
receives 3 argumentsinitialState
(bool) - the initial visual state of theTooltip
containerRef
(ref) - a ref to the container of the tooltip (it should have classwith-tooltip
)elementRef
(ref) - a ref to the element which shows theTooltip
-
and returns:
isVisible
(bool) - visual state of theTooltip
top
(number) - top position of theTooltip
left
(number) - left position of theTooltip
hideTooltip
(func) - a callback used to close theTooltip
showTooltip
(func) - a callback used to open theTooltip
-
Loader
size
(string) - one of the following strings ('mini', 'small', 'medium', 'large', 'extra-large') - specifies size of the Loadertheme
(string) - one of the following string ('dark', 'light') - specifies the theme/color of the loader
-
LoaderScreen
- renders a screen with dark themed extra large Loader in the center -
Bubble
A wrapper of the so called Bubbles in Combined content searchprimary
(bool) - if it is true, a primary class is appended (similar to Origami's approach)filter
(bool) - if the Bubble wrapper is going to be used asFilterBubble
orPreviewBubble
children
(string/node) -children
could be passed to theBubble
in order to fill the content inside it
-
FilterBubble
A Bubble withSelectBox
andCustomAutocomplete
/TextInput
value
(string) - the current value of theTextInput
onChange
(func) - the change handler for theTextInput
initialInputValue
(string) - initial value of theTextInput
dropdownOptions
(array) - options for theSelectBox
autocompleteId
(string/number) - an id for theCustomAutocomplete
autocompleteOptions
(array) - the options for theCustomAutocomplete
autocompleteFinish
(func) - a callback invoked onCustomAutocomplete
finishautocompleteChange
(func) - a callback invoked onCustomAutocomplete
change
-
LogicFilterBubble
A Bubble with logic buttons inside it - AND/OR, Add, Insert, DeleteexpressionValue
(object) - object containingid
andlogic
of the current expressiononChange
(func) - change handler for theRadioInput
(AND/OR filter)addNewFilter
(func) - a callback invoked on "Add new filter" button clickdeleteExpression
(func) - a callback invoked on "Delete group" button clickinsertExpression
(func) - a callback invoked on "Insert" button clickclassName
(string) - an additional class name can be passed from the parent and styles of this class would be applied to theLogicFilterBubble
-
PreviewBubble
A Bubble which is just showing the concept type and the concept and optionally Edit/Show similar concepts/Delete buttontype
(string) - the concept typevalue
(string) - the concept valueprimary
(bool) - if theBubble
wrapper should beprimary
or notactions
(object) - object with actions callbacksedit
anddelete
for tchildren
(string/node)narrower
(array) - an array with narrower concepts to show inSimilarConcept
tooltiprelated
(array) - an array with related concepts to show inSimilarConcept
tooltiponConceptClick
(func) - a callback invoked on Similar concept click
-
Hint
className
(string) - an additional class name can be passed from the parent and styles of this class would be applied to theHint
children
(string/node) -children
could be passed to theHint
in order to fill the content inside it
-
HintConcepts
AHint
with info about the different concept types -
HintLogicGroup
AHint
with info about the different operations -
ExpressionGroup
expression
(object) - an expression/query rendered into thisExpressionGroup
using the differentBubble
s, e.g:
{ id: 1, type: 'expression', logic: 'and', operands: [] }
onChange
(func) - a callback invoked on change of concept typeisFirst
(bool) - indicates if theExpressionGroup
is first of its kindcurrentId
(number) - the current id used in the differentExpressionGroup
sincreaseId
(func) - a callback invoked to increase thecurrentId
dropdownOptions
(array) - dropdown options used insideFilterBubble
withHint
(bool) - indicates if theExpressionGroup
should have hint for using
-
PreviewFilterExpression
Renders an expression in preview modeexpression
(object) - an expression/query rendered into thisExpressionGroup
usingPreviewBubble
, e.g:
{ id: 1, type: 'expression', logic: 'and', operands: [] }
-
Teaser
className
(string) - an additional class name can be passed from the parent and styles of this class would be applied to theTeaser
imageSrc
(string) - the source of the image rendered inside theTeaser
topic
(string) - the topic rendered inside theTeaser
heading
(string) - the heading rendered inside theTeaser
content
(string) - the content rendered inside theTeaser
linkUrl
(string) - iflinkUrl
is passed the whole teaser is rendered as link and leads to the actual article inft.com
-
ArticlesTeasers
date
(string) - a date rendered to every group of articlesarticles
(array) - the articles rendered in this group
-
TimePeriod
isEditable
(bool) - if the time filter is editable or in preview modefrom
(number/string) - the start date of the periodto
(number/string) - the end date of the periodonChange
(func) - a callback invoked on change of the periodembargoPeriod
(bool) - indicates if embargoPeriod checkbox is checkedsetEmbargoPeriod
(func) - a change handler for the embargoPeriod checkbox
-
FeedPreview
expression
(object) - an expression/query rendered into thisExpressionGroup
usingPreviewBubble
, e.g:
{ id: 1, type: 'expression', logic: 'and', operands: [] }
- feed (object) - an object with
period
anditems
properties used to render the feed - isLoading (bool) - indicates if the feed is still loading
- returnToBuilder (func) - a callback invoked on
Return to Buidler
button click
-
useInput
hook for managing text inputs, receives:initialValue
(string) - the initial value of the inputvalidator
(func) - a callback used to validating the input on change
-
and returns:
value
(string) - the current value of the inputonChange
(func) - the change handler of the inputhasError
(bool) - indicates if the input has error (ifvalidator
is passed)isTouched
(bool) - indicates if the input has been touched
-
useExpression
hook for managing expressions/queries, receives:initialExpression
(object) - an initial expression/query, e.g:
{ id: 1, type: 'expression', logic: 'and', operands: [] }
onChangeCallback
(func) - a callback invoked on change of the expression/querycurrentId
(number) - the currentId of all expressionsincreaseId
(func) - a callback invoked to increase thecurrentId
after a new expression is created
-
and returns:
expression
(object) - the new expression/querychangeExpression
(func) - a callback used for updating the expression/querychangeType
(func) - a callback invoked on changing the Logic filter of an expressionchangeFilters
(func) - a callback invoked on changing the filtersinsertExpression
(func) - a callback invoked on inserting an expressiondeleteExpression
(func) - a callback invoked on deletion of an expressiontoggleFilterEditMode
(func) - a callback for togglingeditMode
of a filterchangeConceptType
(func) - a callback invoked for changing the concept typechangeConcept
(func) - a callback invoked for changing the conceptrequestConcepts
(func) - a callback for requesting concepts