1.0.49 • Published 5 months ago

@candourorg/components v1.0.49

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

Candour Component Library

Introduction

The Candour Component Library is a collection of reusable React components designed to simplify the development of user interfaces. This library provides a set of well-crafted components that can be easily integrated into your projects, ensuring a consistent look and feel while saving development time. Whether you're building a small application or a large-scale project, these components are flexible, customizable, and ready to use.

Key Features

  • Customizable Components: Each component comes with a variety of props for customization, allowing you to tailor styles and behavior to your needs.
  • Accessibility: Designed with accessibility in mind to ensure your applications are usable by everyone.
  • Lightweight: The library is lightweight and optimized for performance, ensuring a smooth user experience.
  • Responsive Design: Components are built to be responsive, adapting to different screen sizes seamlessly.

Installation

To install the library, you can use npm or yarn:

npm install @candourorg/ui

or

yarn add @candourorg/ui

or

bun install @candourorg/ui

Button Component

Usage

<Button
  type="submit"
  variant="solid"
  disabled
  plusIcon
  className="submitButton"
  onClick={() => console.log('Button clicked!')}
>
  Submit
</Button>

Dropdown Component

DropdownItem

PropTypeDefaultDescription
childrenReactNode-Dropdown item to display.
itemKeystring-Unique key for the item.
paddingstring-Padding style for the item.
fontstring-Font style for the item.
colorstring-Text color for the item.

DropDownMenu

PropTypeDefaultDescription
childrenReactNode-Dropdown items to display.
bgstring-Background color for the menu.
paddingstring-Padding style for the menu.
sizestring-Size of the menu.
radiusstring-border radius of the DropDown.
shadowstring-box shadow of the DropDown.
onAction(key: string) => void-Called when an item is selected.

DropdownTrigger

PropTypeDefaultDescription
childrenReactNode-Content inside the trigger.

DropdownWrapper

PropTypeDefaultDescription
childrenReactNode-Trigger and menu items.
positionstring-Positioning of the menu.
otherPropsobject-Additional props for context.

Usage

<DropdownWrapper>
  <DropdownTrigger>
    <Button type="button" variant="solid" onClick={() => {}}>
      Trigger Drop Down
    </Button>
  </DropdownTrigger>

  <DropDownMenu
    onAction={handleDropDownAction}
    size="lg"
    radius="md"
    shadow="xl"
  >
    <DropdownItem itemKey="new" text="New file" />
    <DropdownItem itemKey="old" text="Old file" />
  </DropDownMenu>
</DropdownWrapper>

Popover Component

Popover

PropTypeDefaultDescription
popoverIdstring-Unique ID for the popover.
childrenReactNode-Content inside the popover.
closeOnBackdropClickbooleantrueCloses popover on backdrop click.
positionstring-Positioning of the popover.

PopoverTrigger

PropTypeDefaultDescription
childrenReactNode-Content inside the trigger.

PopoverContent

PropTypeDefaultDescription
childrenReactNode-Content inside the popover.
bgstring-Background color for the content.
paddingstring-Padding style for the content.
sizestring-Size of the content.

Usage

<Popover>
  <PopoverTrigger>
    <button>Open Popover</button>
  </PopoverTrigger>
  <PopoverContent variant="solid" position="bottom">
    <p>Popover content (bottom)!</p>
  </PopoverContent>
</Popover>

Modal

PropTypeDefaultDescription
modalIdstring-Unique ID for the modal.
childrenReactNode-Content inside the modal.
closeOnBackdropClickbooleantrueCloses modal on backdrop click.

Usage

<Modal modalId="modalId" closeOnBackdropClick>
  <div>This is the modal content</div>
</Modal>

Toast

Prop NameTypeDefaultDescription
actionstring-Title or label of the toast.
toastIdstring-Unique ID for the toast.
messagestring-Content displayed in the toast.
closeButtonbooleanfalseShows a close button if true.
durationnumber5000Time in milliseconds before the toast automatically closes.
position'top-left' \| 'top-right' \| 'bottom-left' \| 'bottom-right''top-right'Defines the corner of the screen where toasts appear.
variant'default' \| 'success' \| 'error' \| 'info' \| 'warning' \| 'promise''default'Sets the visual style of the toast based on its type.

Usage

<Toast
  action="Success"
  toastId="toastId"
  message="Item deleted successfully."
  variant="info"
  position="top-right"
  closeButton
/>

Toast Container

Usage

Place the ToastContainer at the root of your app or in a specific component

<ToastContainer />

ToggleTheme

-

<ToggleTheme />

Filter Component

Filter

PropTypeDefaultDescription
childrenReactNode-The trigger and menu items of the filter button.
variant'solid' or 'outline''outline'Style variant of the filter button.

FilterTrigger

PropTypeDefaultDescription
labelstring-The text label for the filter button.
arrowDownbooleanfalseIf true, shows an arrow-down icon in the button.
filterIconbooleanfalseIf true, displays a filter icon in the button.
iconPosition'left' or 'right''right'Determines the position of the icon in the button.
classNamestring-Additional class names for custom styling.
disabledbooleanfalseIf true, the button is disabled.

FilterMenu

PropTypeDefaultDescription
childrenReactNode-List of filter items to display in the menu.
onSelectionChange(value: string) => void-Callback when a filter item is selected.
selectedKeystring-Key of the currently selected filter item.
classNamestring-Additional class names for custom styling.

FilterItem

PropTypeDefaultDescription
valuestring-The value that represents the filter item.
childrenReactNode-The content to be displayed in the item.

Usage

<Filter>
  <FilterTrigger
    label="Filter"
    arrowDown
    iconPosition="right"
    variant="solid"
  />

  <FilterMenu onSelectionChange={handleFilterChange} selectedKey={selectedKey}>
    <FilterItem value="new">New Item</FilterItem>
    <FilterItem value="popular">Popular Item</FilterItem>
    <FilterItem value="old">Old Item</FilterItem>
  </FilterMenu>
</Filter>

Sort Component

Sort

PropTypeDefaultDescription
childrenReactNode-The trigger and menu items of the sort component.
onChange(value: string) => void-Callback function triggered when a sort item is selected.

SortTrigger

PropTypeDefaultDescription
labelstring-The text label for the sort button.
arrowDownbooleanfalseIf true, shows an arrow-down icon in the button.
sortIconbooleanfalseIf true, displays a sort icon in the button.
classNamestring-Additional class names for custom styling.
disabledbooleanfalseIf true, the button is disabled.

SortMenu

PropTypeDefaultDescription
childrenReactNode-List of sort items to display in the menu.
onSelectionChange(value: string) => void-Callback when a sort item is selected.
selectedKeystring-Key of the currently selected sort item.
classNamestring-Additional class names for custom styling.

SortItem

PropTypeDefaultDescription
valuestring-The value that represents the sort item.
onClickMouseEventHandler<HTMLLIElement>-Handler called when the item is clicked.
childrenReactNode-The content to be displayed in the item.

Usage

<Sort onChange={handleChange}>
  <SortTrigger sortIcon arrowDown label="Sort" />
  <SortMenu selectedKey={selected} onSelectionChange={handleChange}>
    {data.map((item) => (
      <SortItem value={item.value} key={item.label}>
        {item.label}
      </SortItem>
    ))}
  </SortMenu>
</Sort>

DatePicker Component

RegularDatePicker

The RegularDatePicker component is a flexible and customizable. It allows users to select a single date or a date range, with support for various configurations such as date format, display options, and accessibility features.

Features

  • Supports both single-date and range selection.
  • Customizable date format for display and input.
  • Optional footer and shortcut options to improve usability.
  • Min and Max date restrictions to ensure valid date selection.

Example Usage

Below are two examples demonstrating how to use the RegularDatePicker component in a React application: one in range mode and the other in single-date mode.

Example 1: Date Range Selection (Range Mode)

In this example, the RegularDatePicker allows users to select a range of dates. The useRange prop is set to true, and asSingle is set to false.

import React, { useState } from 'react';
import { RegularDatePicker } from '@candour-ui/react';

const DateRangePickerExample: React.FC = () => {
  const [value, setValue] = useState<DateRange>({
    startDate: null,
    endDate: null,
  });

  console.log(value);

  return (
    <RegularDatePicker
      useRange={true}
      label="Select a Date Range"
      placeholder="Select date range"
      asSingle={false}
      value={value}
      displayFormat={'DD/MM/YYYY'}
      onChange={(newValue: DateValueType) => setValue(newValue as DateRange)}
    />
  );
};

Example 2: Single-Date Selection (Single Mode)

In this example, the RegularDatePicker is configured for selecting a single date. The useRange prop is set to false, and asSingle is set to true.

import React, { useState } from 'react';
import { RegularDatePicker } from '@candour-ui/react';

const DateRangePickerExample: React.FC = () => {
  const [value, setValue] = useState<DateRange>({
    startDate: null,
    endDate: null,
  });

  console.log(value);

  return (
    <RegularDatePicker
      useRange={false}
      label="Select a Date Range"
      placeholder="Select date range"
      asSingle={true}
      value={value}
      displayFormat={'DD/MM/YYYY'}
      onChange={(newValue: DateValueType) => setValue(newValue as DateRange)}
    />
  );
};

Key Differences Between Range Mode and Single-Date Mode

The RegularDatePicker component can be used in two distinct modes: Range Mode and Single-Date Mode. Below is a comparison of the key differences between these modes:

FeatureRange ModeSingle-Date Mode
useRange PropSet to true to enable range selection.Set to false to disable range selection.
asSingle PropSet to false to allow selecting a range of dates.Set to true for selecting a single date.
PurposeAllows selecting a start and end date, ideal for booking systems and event scheduling.Allows selecting only one date, ideal for picking specific dates like birthdays.
Value TypeManaged as a DateRange object with startDate and endDate.Managed as a single DateValueType.

By toggling the useRange and asSingle props, you can easily switch between range and single-date selection modes to fit your specific use case.

Regular Date Comprehensive Props Guide

Prop NameTypeRequiredDescription
primaryColorColorKeysNo (Optional)Primary color for styling the date picker.
valueDateValueTypeYesThe current value of the date picker.
onChange(value: DateValueType, e?: HTMLInputElement \| null \| undefined) => voidYesCallback triggered when the date value changes.
useRangebooleanNo (Optional)Whether to allow selecting a range of dates.
showFooterbooleanNo (Optional)Whether to show footer actions in the date picker.
showShortcutsbooleanNo (Optional)Whether to show shortcut options in the date picker.
configsConfigsNo (Optional)Additional configuration options for the date picker.
asSinglebooleanNo (Optional)Whether the picker operates in single-date selection mode.
placeholderstringNo (Optional)Placeholder text displayed in the date picker input.
separatorstringNo (Optional)Separator text for date ranges.
startFromDateTypeNo (Optional)Initial date or month to display when the picker opens.
i18nstringNo (Optional)Internationalization key for locale settings.
disabledbooleanNo (Optional)Whether the date picker is disabled.
classNamesClassNamesTypePropNo (Optional)Custom class names for styling.
containerClassNameClassNameTypeNo (Optional)Class name for the container element.
popupClassNameClassNameTypeNo (Optional)Class name for the popup element.
inputClassNameClassNameTypeNo (Optional)Class name for the input field.
toggleClassNameClassNameTypeNo (Optional)Class name for the toggle button.
toggleIcon(open: boolean) => ReactNodeNo (Optional)Custom toggle icon component.
inputIdstringNo (Optional)ID for the input field.
inputNamestringNo (Optional)Name attribute for the input field.
displayFormatstringNo (Optional)Format in which the selected date(s) are displayed.
readOnlybooleanNo (Optional)Whether the input field is read-only.
minDateDateTypeNo (Optional)Minimum selectable date.
maxDateDateTypeNo (Optional)Maximum selectable date.
dateLookingDateLookingTypeNo (Optional)Type of date selection behavior.
disabledDatesDateRangeType[]No (Optional)Array of date ranges to disable.
startWeekOnWeekStringTypeNo (Optional)The day of the week to start on (e.g., Sunday or Monday).
popoverDirectionPopoverDirectionTypeNo (Optional)Direction in which the popover opens (e.g., top, bottom).
requiredbooleanNo (Optional)Whether the date picker is required.

FormikDatePicker

FormikDatePicker is a React component designed for use with Formik to handle single-date input fields in forms. It supports selecting only one date.


Key Features:

  • Single-Date Selection: For selecting one date.
  • Formik Integration: Seamlessly works with Formik for form state and validation.
  • Customizable: Easily configure label, error messages, and more.

Example Usage

The following example demonstrates how to use FormikDatePicker with Formik, including form validation using Yup.

import { Button, FormikDatePicker } from '@candour-ui/react';

const DatePickerFormik: React.FC = () => {
  const validationSchema = Yup.object().shape({
    startDate: Yup.string().required('Start Date is required').nullable(),
  });

  const companyTaxFormvalues = {
    startDate: '',
  };

  return (
    <Formik
      initialValues={companyTaxFormvalues}
      validationSchema={validationSchema}
      onSubmit={(values) => {
        console.log(values);
      }}
    >
      {(formikProps: FormikProps<any>) => {
        const { values, errors } = formikProps;

        return (
          <Form className="flex flex-col h-[calc(100vh-48px)]">
            <div className="flex items-center gap-5">
              <div className="grow">
                <Field
                  type="date"
                  id="startDate"
                  name="startDate"
                  label="Start Date"
                  placeholder="Choose a date"
                  value={values.startDate}
                  component={FormikDatePicker}
                  showError={!!errors.startDate}
                  errorMessage={errors.startDate}
                  form={formikProps}
                />
              </div>
            </div>
            <div className="flex-none">
              <Button
                type="submit"
                disabled={false}
                isSubmitting={false}
                className="w-full mt-3"
              >
                Submit
              </Button>
            </div>
          </Form>
        );
      }}
    </Formik>
  );
};

Formik Date Picker Comprehensive Props Guide

Prop NameTypeRequiredDescription
valueDateYesThe current value of the date picker.
labelstringYesLabel text for the date picker.
disabledbooleanYesWhether the date picker is disabled.
showErrorbooleanYesControls the visibility of error messages.
errorMessagestringYesError message displayed when validation fails.
placeholderstringNo (Optional)Placeholder text displayed in the date picker.
showFooterbooleanNo (Optional)Whether to show footer actions in the date picker.
showShortcutsbooleanNo (Optional)Whether to show shortcut options in the date picker.
displayFormatstringNo (Optional)The format in which the selected date is displayed.
minDateDateValueTypeNo (Optional)Minimum selectable date.
1.0.49

5 months ago

1.0.48

5 months ago

1.0.47

5 months ago

1.0.46

6 months ago

1.0.45

6 months ago

1.0.44

6 months ago

1.0.41

6 months ago

1.0.42

6 months ago

1.0.40

6 months ago

1.0.39

6 months ago

1.0.38

6 months ago

1.0.37

6 months ago

1.0.36

6 months ago

1.0.35

6 months ago

1.0.34

6 months ago

1.0.33

6 months ago

1.0.32

6 months ago

1.0.31

6 months ago

1.0.30

6 months ago

1.0.29

6 months ago

1.0.28

6 months ago

1.0.27

6 months ago

1.0.26

6 months ago

1.0.25

7 months ago

1.0.24

7 months ago

1.0.23

7 months ago

1.0.22

7 months ago

1.0.21

7 months ago

1.0.20

8 months ago

1.0.19

8 months ago

1.0.18

8 months ago

1.0.17

8 months ago

1.0.16

8 months ago

1.0.15

8 months ago

1.0.14

8 months ago

1.0.13

8 months ago

1.0.12

8 months ago

1.0.11

8 months ago

1.0.10

8 months ago

1.0.9

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago