React Rainbow Components

repository·master·Indexed 23 days ago

https://github.com/nexxtway/react-rainbow

A collection of over 90 accessible, TypeScript-ready React components for building web applications. Version 1.32.0 includes components such as Accordion, AccordionSection, ActivityTimeline, and TimelineMarker, featuring support for controlled states, custom icons, and multiple layout variants.

Tokens
145.7K
Snippets
315
Records
542
Agent score
82%

What's inside react-rainbow-components

  1. Add icons and checkboxes to Tree nodes

    master

    The Tree component supports visual enhancements through the icon and isChecked properties in the data objects.

    • Icons: Pass any React element (e.g., <FileIcon />) to the icon property of a node.
    • Checkboxes: Use the isChecked property. It supports true, false, and 'indeterminate' states. Use the onNodeCheck prop to handle user interactions and implement logic for parent/child selection synchronization.
    const data = [
        { 
            label: 'Tree Item', 
            icon: <FileIcon />, 
            isChecked: false 
        },
        {
            label: 'Tree Branch',
            icon: <FolderCloseIcon />,
            children: [
                { label: 'Child Item', isChecked: true }
            ]
        }
    ];
  2. Configure Drawer position and size

    master

    You can customize the visual presentation of the Drawer using the slideFrom and size props.

    Slide Direction

    Use the slideFrom prop to specify the entry animation direction:

    • slideFrom="right"
    • slideFrom="left"

    Drawer Sizes

    Use the size prop to set the width of the drawer. Supported values are:

    • small
    • medium
    • large
    • full (covers the entire screen)
    <Drawer
        header="This is a drawer"
        slideFrom="right"
        size="large"
        isOpen={state.isOpen}
        onRequestClose={() => setState({ isOpen : false })}
    />
  3. Group Lookup options into sections

    master

    The Lookup component supports grouping options into labeled sections. To do this, pass an array to options where some objects have a type: 'section' property. These section objects must contain a label for the section header and an options array containing the actual selectable items.

    const data = [
        {
            type: 'section',
            label: 'European Cities',
            options: [
                { label: 'Paris', icon: <FontAwesomeIcon icon={faBuilding} /> },
                { label: 'Madrid', icon: <FontAwesomeIcon icon={faBuilding} /> },
            ],
        },
        {
            type: 'section',
            label: 'American Cities',
            options: [
                { label: 'New York', icon: <FontAwesomeIcon icon={faBuilding} /> },
            ],
        },
    ];
    
    <Lookup
        options={data}
        // ...
    />
  4. Configure Tabset variants and layouts

    master

    The Tabset component supports different visual styles and layout behaviors:

    1. Full Width Layout: Use the fullWidth prop to make the tabs stretch across the container.
    2. Line Variant: Use variant="line" to display the tab indicator as a line (often used for a more minimal look).
    3. Dynamic Tabs: Since Tabset is a standard React component, you can conditionally render Tab children based on component state to add or remove tabs dynamically.
  5. Use the Accordion component

    master

    The Accordion component is a container for AccordionSection components. It allows users to expand or collapse sections of content. You can use it as a basic container or extend its functionality with props like multiple to allow several sections to be open at once, or activeSectionNames to control which sections are currently expanded.

    import React from 'react';
    import { Accordion, AccordionSection } from 'react-rainbow-components';
    
    <Accordion id="accordion-1">
        <AccordionSection label="Section Label">
            Content goes here.
        </AccordionSection>
    </Accordion>
  6. How PathStep and Path work together

    master

    The PathStep component cannot be used in isolation. It must be composed within a Path component. To identify a specific step within the path, you must provide a required name prop to each PathStep. The Path component uses the currentStepName prop to determine which step is currently active.

    import React from 'react';
    import { Path, PathStep } from 'react-rainbow-components';
    
    const BasicPath = () => {
        return (
            <div className="rainbow-p-around_x-large rainbow-align-content_center">
                <Path currentStepName="arrived">
                    <PathStep name="scheduled" label="Scheduled" />
                    <PathStep name="in-progress" label="InProgress" />
                    <PathStep name="arrived" label="Arrived" />
                    <PathStep name="delivered" label="Delivered" />
                </Path>
            </div>
        );
    };
  7. Use the Tabset page object for automated testing

    master

    The PageTabset page object allows you to interact with the Tabset component in automated tests (e.g., using WebdriverIO). You can instantiate it with the CSS selector of the Tabset component and use it to retrieve individual tab items for interaction.

    Key methods include:

    • getItem(index): Returns a representation of the tab item at the specified zero-based index.
    • tabItem.click(): Selects the tab.
    • tabItem.isSelected(): Returns a boolean indicating if the tab is currently selected.
    • tabItem.hasFocus(): Returns a boolean indicating if the tab currently has focus.
    const PageTabset = require('react-rainbow-components/components/Tabset/pageObject');
    
    const TABSET = '#tabset-1';
    const tabset = new PageTabset(TABSET);
    
    // Get the first tab
    const tabItem = tabset.getItem(0);
    
    // Interact with the tab
    tabItem.click();
    console.log(tabItem.isSelected()); // true
  8. Use the Textarea component

    master

    The Textarea component from react-rainbow-components provides a multi-line text input field. It supports various configurations including labels, placeholders, rows, and different visual styles like shaded variants or specific border radii.

    import React from 'react';
    import { Textarea } from 'react-rainbow-components';
    
    const containerStyles = {
        maxWidth: 700,
    };
    
    <Textarea
        id="example-textarea-1"
        label="Textarea Label"
        rows={4}
        placeholder="Placeholder Text"
        style={containerStyles}
        className="rainbow-m-vertical_x-large rainbow-p-horizontal_medium rainbow-m_auto"
    />
  9. Use the DateTimePicker Page Object for testing

    master

    The PageDateTimePicker page object from react-rainbow-components provides a high-level API for interacting with and asserting the state of the DateTimePicker component during automated testing (e.g., using WebdriverIO).

    To use it, import the page object and instantiate it with the CSS selector of your component instance. You can then use its methods to simulate user interactions like clicking the input, clicking the label, selecting dates, and interacting with the OK/Cancel buttons, as well as asserting whether the picker is open or retrieving its current value.

  10. Add dynamic row actions to a Table

    master

    If actions must change based on row data (e.g., hiding 'Delete' for verified users), do not use type="action". Instead, provide a custom component to the component prop of a Column.

    When the Table instantiates your custom component, it passes two key props:

    1. value: The value of the field specified by the field prop.
    2. row: The full data object for that row.

    You can use these props within your custom component to conditionally render MenuItems inside a ButtonMenu or ButtonGroup.

    const MenuAction = ({ value, name }) => {
        if(value === 'verified'){
            return  <MenuItem label="Delete" />
        }
        return (
            <>
                <MenuItem label="Delete" onClick={() => console.log(`Delete ${name}`)}/>
                <MenuItem label="Edit" onClick={() => console.log(`Edit ${name}`)}/>
            </>
        );
    };
    
    const ButtonAction = props => {
        const { value, row:{ name } }=props;
        return (
            <ButtonMenu
                id="button-menu-2"
                menuAlignment="right"
                menuSize="x-small"
                icon={<FontAwesomeIcon icon={faEllipsisV} />}
                buttonVariant="base"
                className="rainbow-m-left_xx-small"
            >
                <MenuAction value={value} name={name}/>
            </ButtonMenu>
        );
    }
    
    // Usage in Table
    <Table keyField="id" data={DynamicDataTable}>
        <Column header="Name" field="name" />
        <Column header="Status" field="status" component={StatusBadge} />
        <Column header="Company" field="company" />
        <Column header="Email" field="email" />
        <Column field="status" component={ButtonAction} width={60}/>
    </Table>
  11. Integrate MonthlyCalendar with a Drawer for event details

    master

    You can create an interactive experience by combining MonthlyCalendar with a Drawer. When a user selects a date via onSelectDate, you can update your local state to open a Drawer and pass the selected date's data (e.g., a list of tasks) into the drawer's content area.

    // 1. Setup state to manage selection and drawer visibility
    const [state, setState] = useState({
        currentMonth: new Date('2019-12-06'),
        selectedDate: undefined,
        isOpen: false,
    });
    
    // 2. Use MonthlyCalendar to trigger the drawer
    <MonthlyCalendar
        currentMonth={state.currentMonth}
        selectedDate={state.selectedDate}
        onSelectDate={({ date }) => setState({ selectedDate: date, isOpen: true })}
        onMonthChange={({ month }) => setState({ currentMonth: month })}
        dateComponent={date => (
            <DailyTasks
                availableTasksCount={getAvailableTasksCountForDate(date, tasksList)}
                assignedTasksCount={getAssignedTasksCountForDate(date, tasksList)}
            />
        )}
    />
    
    // 3. Display details in the Drawer
    <Drawer
        slideFrom="right"
        header={<StyledTitle>{getFormattedDate(state.selectedDate)}</StyledTitle>}
        isOpen={state.isOpen}
        onRequestClose={() => setState({ isOpen: false })}
    >
        <DrawerTasks
            date={state.selectedDate}
            tasks={tasksList}
        />
    </Drawer>