NeoPOP Web

repository·main·Indexed 21 days ago

https://github.com/cred-club/neopop-web

CRED's internal design system library for web applications. NeoPOP provides a collection of React components, primitives, hooks, and utilities designed to implement the NeoPOP design language, with components currently optimized for mobile views. It includes specialized elements such as the Button (supporting flat, elevated, and link kinds), BottomSheet, and Checkbox, along with the useBottomSheet hook for managing mounting state and body scroll locking.

Tokens
33.2K
Snippets
100
Records
131
Agent score
75%

What's inside @cred/neopop-web

  1. Tag component variants

    main

    The Tag component supports several semantic variants through the colorConfig prop, typically using predefined guides like colorGuide:

    • Success: Uses colorGuide.lightComponents.tags.success or colorGuide.darkComponents.tags.success.
    • Info: Uses colorGuide.lightComponents.tags.info. Can include an icon prop with a URL.
    • Error: Uses colorGuide.darkComponents.tags.error.
    • Warning: Uses colorGuide.lightComponents.tags.warning.
    • No Container: Setting noContainer={true} removes the background/container styling.
    // Example of an Info variant with an icon
    <Tag
        colorConfig={colorGuide.lightComponents.tags.info}
        icon="https://example.com/icon.png"
    >
        Info with icon
    </Tag>
  2. Button Sizes and Styles

    main

    Sizes

    The size prop determines padding, height, and typography style. Supported values:

    • big
    • medium
    • small

    Visual Styles

    You can modify the button's appearance using:

    • showArrow: Adds an arrow icon to the button.
    • icon: Accepts a URL string to display an image icon aligned to the left of the text.
    • fullWidth: A boolean that makes the button take up the full width of its container.
  3. Button Kinds and Variants

    main

    The Button component supports different visual styles through kind and variant props:

    Kinds

    • flat: A flat-style button.
    • elevated: A neoPOP elevated button with depth.
    • link: A link-style button (typically used with a specific color).

    Variants

    For flat and elevated kinds, you can specify a variant:

    • primary: The primary action style.
    • secondary: The secondary action style.
  4. Choosing between Header and Back components

    main

    The library provides two components for page navigation and information, which differ in their visual design and layout purpose:

    • Header: Use this for block-level headings. It supports both a heading and an optional description.
    • Back: Use this for inline-level headings. It is a more compact design typically used for simple navigation back actions.
  5. Use the Toggle component

    main

    The Toggle component allows users to switch a single option on or off, typically used for enabling or disabling settings. It is a controlled component that requires an isChecked state and an onChange handler to manage its value.

    import React, { useState } from 'react';
    import { Toggle } from '@cred/neopop-web/lib/components';
    import { colorGuide } from '@cred/neopop-web/lib/primitives';
    
    const ToggleButton = () => {
        const [isChecked, setIsChecked] = useState(false);
        const handleChange = (event) => {
            console.log(event.target.checked);
            setIsChecked(event.target.checked);
        };
    
        return (
            <Toggle
                isChecked={isChecked}
                colorConfig={colorGuide.lightComponents.toggle}
                onChange={handleChange}
            />
        );
    };
  6. Use the ElevatedCard component

    main

    The ElevatedCard component creates a card effect with visual 'plunks' (depth accents) at the right and bottom edges. To use it, wrap your card content inside the ElevatedCard component. You can customize the card's appearance using backgroundColor and edgeColors to define the specific colors for the bottom and right depth accents.

    import React from 'react';
    import {
        ElevatedCard,
        Column,
        Row,
        Typography,
        HorizontalSpacer,
        Tag,
        Button,
    } from '@cred/neopop-web/lib/components';
    import {
        mainColors,
        colorPalette,
        fontNameSpaces,
        getButtonConfig,
    } from '@cred/neopop-web/lib/primitives';
    import styled from 'styled-components';
    
    const ContentWrapper = styled.div`
        padding: 20px;
    `;
    
    const Card = () => {
        return (
            <ElevatedCard
                backgroundColor="#AE275F"
                edgeColors={{
                    bottom: '#5C1532',
                    right: '#851E49',
                }}
                style={{
                    width: '230px',
                }}
            >
                <ContentWrapper>
                    <Column>
                        {/* Your card content here */}
                    </Column>
                </ContentWrapper>
            </ElevatedCard>
        );
    };
    
    export default Card;
  7. Use the Tag component

    main

    The Tag component is used to label, categorize, or organize data using keywords. It can be customized with specific color configurations, icons, and text styles.

    import { Tag } from '@cred/neopop-web/lib/components';
    import { mainColors } from '@cred/neopop-web/lib/primitives';
    
    const TagUsage = () => {
        return (
            <Tag colorConfig={{ color: mainColors.blue, background: mainColors.white }}>
                DEAL OF THE DAY
            </Tag>
        );
    };
    
    export default TagUsage;
  8. Use PageContainer for page padding

    main

    Wrap your page content in PageContainer to apply consistent design system paddings. The component applies a padding-right of 15px and a padding-left of 30px.

    import React from 'react';
    import { PageContainer } from '@cred/neopop-web/lib/components';
    
    const Page = ({ children }) => {
        return <PageContainer>{children}</PageContainer>;
    };
    
    export default Page;
  9. How to use Toasts

    main

    Toasts are non-blocking notifications used to display short messages to users. To implement them, follow these two steps:

    1. Mount the Container: Add the <ToastContainer /> component anywhere in your application's DOM tree (typically at the root level).
    2. Trigger a Toast: Call the showToast method, passing the message as the first argument and a configuration object as the second.

    You can use predefined types (success, error, warning) or provide a custom colorConfig to override the appearance.

    // 1. Setup Container in App.jsx
    import { ToastContainer } from '@cred/neopop-web/lib/components';
    
    const App = () => (
        <div>
            <ToastContainer />
            <MainApp />
        </div>
    );
    
    // 2. Trigger Toast in a component
    import { showToast } from '@cred/neopop-web/lib/components';
    
    const MyComponent = () => {
        const handleClick = () => {
            showToast('Sample toast message', { 
                type: 'success', 
                autoCloseTime: 5000 
            });
        };
    
        return <button onClick={handleClick}>Click for toast</button>;
    };
  10. Use the ScoreMeter component

    main

    The ScoreMeter component provides a visual representation of a quantifiable value within a defined range.

    To use it:

    1. Pass the required reading prop.
    2. Set lowerLimit and upperLimit to define the scale (defaults are 300 and 900 respectively).
    3. Use colorMode ("dark" or "light") to set the theme.
    4. Use type ("excellent", "average", or "poor") to automatically set colors based on the rating.
    5. Provide oldReading if you want to trigger a transition animation from a previous value to the current reading.
    import { ScoreMeter } from '@cred/neopop-web/lib/components';
    
    const ScoreMeterExample = () => {
        return (
            <ScoreMeter
                reading={720}
                oldReading={500}
                lowerLimit={100}
                upperLimit={1000}
                colorMode="light"
                type="excellent"
            />
        );
    };
    
    export default ScoreMeterExample;
  11. Use the InputField component

    main

    The InputField component provides a labeled text input field. It supports various input types, error states, and extensive styling via colorConfig and textStyle props.

    import React from 'react';
    import { InputField } from '@cred/neopop-web/lib/components';
    
    const InputFieldExample = () => {
        return (
            <div>
                <InputField
                    type="text"
                    label="your name"
                    placeholder="enter your name"
                    id="text_field"
                    autoFocus
                />
            </div>
        );
    };
    
    export default InputFieldExample;
  12. Use the SearchBar component

    main

    The SearchBar component provides a flexible search input field that supports both icon rendering and event handling for input changes and form submissions. You can use it with or without an icon by providing or omitting the iconUrl prop.

    import React from 'react';
    import { SearchBar } from '@cred/neopop-web/lib/components';
    import { colorGuide } from '@cred/neopop-web/lib/primitives';
    
    const SearchInputField = () => {
        const handleChange = (value) => {
            console.log('Search query: ', value);
        };
        const handleSubmit = () => {
            console.log('Search query submitted');
        };
    
        return (
            <SearchBar
                iconUrl="https://cdn-icons-png.flaticon.com/512/482/482631.png"
                placeholder="search query here"
                colorConfig={colorGuide.lightComponents.searchBar}
                inputColorConfig={colorGuide.lightComponents.inputFields}
                handleSearchInput={handleChange}
                onSubmit={handleSubmit}
            />
        );
    };
    
    export default SearchInputField;