Alfa Laboratory Core Components

repository·master·Indexed 40 days ago

https://github.com/alfa-laboratory/core-components

A React component library for building web interfaces aligned with the Alfa-Bank design system. Version 26.4.0 provides TypeScript support, accessibility, and theming via CSS variables. The library is distributed as a monorepo allowing for granular installation of individual components or the full package. Includes a codemod tool (@alfalab/core-components-codemod) for migrating components from arui-feather and updating button styles.

Tokens
175.9K
Snippets
581
Records
721
Agent score
49%

What's inside Alfa Laboratory Core Components

  1. Overview of Core Components library

    master

    The @alfalab/core-components library is a collection of React components designed for building web interfaces. Key features include:

    • Tested Components: Up-to-date and verified components.
    • Design System Alignment: Built to comply with the Alfa-Bank design system.
    • TypeScript Support: Fully typed for better developer experience and safety.
    • Themable: Easily customizable using CSS variables.
    • Accessible: Designed to meet accessibility requirements.
    • Maintained: Supported by a dedicated team.
  2. Use the IntlPhoneInput component

    master

    The IntlPhoneInput component is a text field designed for entering international phone numbers. It uses the libphonenumber-js library (approx. 140KB) for phone number formatting.

    Important Build Note: libphonenumber-js is bundled into a separate chunk. When building your project, ensure that this library is also collected into its own separate chunk to optimize performance. If you are using arui-scripts for your build process, ensure you are using version 9.7.0 or higher.

  3. Use Typography components for text styling

    master

    The @alfalab/core-components-typography package provides a set of components implementing a hybrid typography system. It includes specialized components for titles (standard, mobile-only, and responsive) and general text styling.

    Key Rules:

    • Font Family: Components do not set the font-family property unless the font='styrene' option is used. It is assumed that the font is already set on a parent element.
    • Color: Use the color prop for static elements. For interactive elements that require color changes on hover, you should apply colors via CSS instead of using the color prop.
  4. Configure image downloading in Plate

    master

    When using the Plate component to display information or content related to image downloads, ensure that the server response includes the header content-disposition: attachment. This ensures that browsers trigger a download rather than attempting to navigate to or display the image in the browser tab.

    <Plate
        view='common'
        leftAddons={
            <Badge view='icon' iconColor='secondary' content={<InformationCircleMIcon />} />
        }
    >
        <span>
            Чтобы скачивание изображений работало корректно, убедитесь, что в ответе от сервера
            выставлен заголовок <b>content-disposition: attachment</b>
        </span>
    </Plate>
  5. Understand component readiness statuses

    master

    The @alfalab/core-components library uses a status system to communicate the maturity and readiness of a component for production use. Developers should check the status before deciding whether to implement a component in a critical product path.

    StageStatusCriteria
    0ProposalAn Issue exists describing the requirements for a new component.
    1DraftThe component is implemented and published, but has not been tested in any products.
    2CandidateThe component has been tested in at least one product, has clear documentation with usage examples, and is ready for implementation.
    3RecommendationThe component has been tested in at least two products and is officially recommended for implementation.
  6. How the Stack component manages z-index layering

    master

    The Stack component provides a centralized way to manage the stacking order of floating components (like tooltips, modals, and toasts).

    Without Stack, developers often manually assign z-index values to components. This leads to two main problems:

    1. Layering conflicts: A tooltip inside a modal might be hidden by the modal if its z-index is lower, or it might incorrectly appear above the modal if its z-index is higher.
    2. Lack of centralized control: There is no single source of truth for layering, forcing developers to manually track and guess the z-index values of other components to ensure correct visibility.

    Stack solves this by using a stackingOrder dictionary. When a component is rendered within another (e.g., a Tooltip inside a Modal), Stack ensures the inner component's z-index is incremented relative to its parent's layer, maintaining the correct visual hierarchy.

  7. Theming constraints and best practices

    master

    When implementing theming with @alfalab/core-components, adhere to the following constraints to avoid visual bugs and CSS conflicts:

    1. Single Theme per Page: A single page should use only one theme (e.g., the mobile theme). Mixing themes on a single page is not supported.
    2. Single Color Palette per Page: Only one color palette should be active on a single page. The default palette is bluetint. If your project requires multiple palettes (e.g., bluetint and indigo), you must load them via separate CSS bundles or by inserting a <style> tag containing the specific palette on the required page. Otherwise, colors will overwrite each other in the final CSS bundle.
    3. Dark Mode Scope: Dark mode is applied to the entire page. You cannot use dark mode to recolor individual blocks. If you need a specific component to have an inverted color scheme without changing the whole page, use the component's inverted version instead of the global dark mode.
  8. Use ModalContext to create custom components

    master

    The Modal component provides a ModalContext that allows you to build custom headers, footers, and content areas while maintaining synchronization with the modal's internal state (like scroll position and presence of UI elements).

    To create a custom header or footer that correctly informs the modal of its existence (to adjust padding/margins), you must call setHasHeader(true) or setHasFooter(true) within a useEffect hook inside your custom component.

    const Header = () => {
        const { setHasHeader } = React.useContext(ModalContext);
    
        // Notify the modal that a header is being rendered
        React.useEffect(() => setHasHeader(true), [setHasHeader]);
    
        return (
            <div style={{ /* styles */ }}>
                Шапка
            </div>
        );
    };