animal-island-ui

repository·main·Indexed 26 days ago

https://github.com/guokaigdg/animal-island-ui

A lightweight React and TypeScript UI component library inspired by the Animal Crossing: New Horizons interface. It features a nature-inspired design system with warm earth tones, 3D buttons, and 30 components including NookPhone-style grids, themed cards, and custom animations. The library uses a dual design token system (Less variables and CSS custom properties) for runtime re-theming and follows a zero-runtime dependency architecture.

Tokens
49K
Snippets
86
Records
272
Agent score
87%

What's inside animal-island-ui

  1. Overview of the animal-island-ui Design System

    main

    animal-island-ui is a React + TypeScript UI component library inspired by Animal Crossing: New Horizons. The design language is characterized by a warm earth-tone palette, large-radius pill shapes, 3D depth for buttons, soft motion, and a mix of geometric and organic shapes.

    Technical Implementation

    • Core Tech: React + TypeScript
    • Styling: Less Modules using design tokens defined in src/styles/variables.less
    • Build Tool: Vite (library mode)
    • Component Source: Located in src/components/<ComponentName>/
  2. Use animal-island-ui-style for React projects or Standalone HTML

    main

    The animal-island-ui-style skill supports two primary development scenarios:

    1. React project: Uses the official animal-island-ui npm package. This includes setup instructions, API exploration via TypeScript declarations, component recipes, and theming using --animal-* design tokens.
    2. Standalone HTML: Generates a single, self-contained index.html file using React via CDN and the Babel runtime. This approach hand-rolls components to mirror the real API without requiring a build step.
  3. License and Usage Restrictions for Animal-Island-UI

    main

    Animal-Island-UI is licensed under Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0).

    Permitted Uses (Non-Commercial)

    • Personal learning and research.
    • Evaluation and testing.
    • Non-commercial demonstrations.

    Prohibited Uses

    • Commercial use is strictly prohibited. This includes any form of commercial products, enterprise projects, external services, or paid templates.
    • Reselling or profiting from the component library is forbidden.

    Requirements

    • You must retain the original author's copyright and license notices when using this library.

    Disclaimer

    • This project is not an official Nintendo product and has no affiliation, authorization, or partnership with Nintendo Co., Ltd. The project name and styles are for descriptive and inspirational purposes only.
  4. Understand the Dual Design Token System

    main

    Animal-Island-UI uses a two-layer design token system to balance component authoring flexibility with runtime re-theming capabilities.

    1. Less Compile-time Variables: Located in src/styles/variables.less, these are @-prefixed variables (e.g., @primary-color). They are used for values that require computation, such as darken(), lighten(), or media query conditions. These are substituted as literals during compilation and are not available at runtime.

    2. Runtime CSS Custom Properties: Located in src/styles/themes/default.less, these are --animal-* prefixed properties (e.g., --animal-primary-color). They are initialized from the Less variables and allow consumers to re-theme the library in the browser without rebuilding the code.

    Authoring Rule:

    • Use var(--animal-*) by default for component styles.
    • Use Less variables (@...) only when the value must be known at compile time (e.g., for color functions, mixin arguments, or media queries).
  5. Usage and License Restrictions for Animal-Island-UI

    main

    Usage Cases

    Animal-Island-UI is used to create Animal Crossing-themed interfaces for various platforms, including:

    • New tab pages
    • Personal website templates
    • Android and Flutter UI libraries
    • Blogs and photo journals
    • Educational apps (e.g., English learning or Math practice)
    • Desktop applications (Tauri/CLI)
    • Astro themes

    This project is strictly for personal learning, research, and non-commercial demonstration only.

    • Commercial Use Prohibited: You may NOT use this library in any commercial product, enterprise project, external service, or paid template. Any form of resale or profit-making activities is prohibited.
    • No Association with Nintendo: This is not an official Nintendo product. The name and styles are used for descriptive reference and design inspiration only.
    • License: Distributed under Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0).
    • Requirements: You must retain the original copyright notice and license declaration.
    • Risk: Users are solely responsible for any risks arising from the use of this component library.
  6. Understand the animal-island-ui tech stack

    main

    The animal-island-ui library is a React + TypeScript UI component library. Key technical specifications include:

    • Framework: React 18 (supports peerDependencies >= 17)
    • Language: TypeScript 5.7 with strict: true enabled
    • Build Tool: Vite 7 (outputs dual ES + CJS in dist/)
    • Styling: Less Modules (*.module.less)
    • Testing: Vitest 4, jsdom 29, and @testing-library/react 16
    • Accessibility: axe-core 4 and vitest-axe
    • Runtime Requirements: Node.js >= 18
  7. Understand the dependency model of animal-island-ui

    main

    The animal-island-ui library follows a Zero Runtime Dependencies architecture. It does not include any packages in its dependencies field to prevent enlarging your application's install footprint or causing version conflicts (such as duplicate React instances).

    Instead, it uses peer dependencies. This means the library expects your host application to provide the following packages:

    • react (version >=17.0.0)
    • react-dom (version >=17.0.0)
    • classnames (version ^2.5.1)

    Note for package managers:

    • If you use npm 7+, missing peer dependencies are installed automatically.
    • If you use pnpm (without auto-install-peers) or older versions of npm, you must manually install classnames to avoid unmet-peer warnings.
  8. Understand the Animal-Island-UI build architecture and tree-shaking

    main

    The library is built using Vite in library mode with preserveModules: true and preserveModulesRoot: 'src'. This architecture ensures that the library is not shipped as a single monolithic bundle. Instead, it produces one output file per source module (ES and CJS), allowing consumer bundlers to perform effective tree-shaking.

    Key architectural features:

    • Per-component tree-shaking: Consumers only bundle the components, fonts, and images they actually import.
    • CSS Code Splitting: Stylesheets are split along the same boundaries as the components via cssCodeSplit: true.
    • Asset Management: Fonts and images are emitted as content-hashed files under dist/files/ rather than being inlined as data URIs.
    • Subpath Exports: The library provides specific entry points for styles (animal-island-ui/style) and item icons (animal-island-ui/items/*).
  9. Implement component logic and styles

    main

    Follow these implementation conventions for all components:

    • Typing: Use React.FC<Props>. Name the interface <Name>Props and export it with export type.
    • Props: Use JSDoc for every prop (Chinese comments are the house style). Use destructuring for default values instead of defaultProps.
    • Attributes: Extend native element attributes using Omit to redefine specific fields (e.g., extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'type'>).
    • Class Names: Compose classes using the classnames library or the [styles.a, cond && styles.b].filter(Boolean).join(' ') pattern.
    • Identity: Always set displayName on the component.
    • State: Stateful components must support both controlled (value) and uncontrolled (defaultValue) usage.
    • Naming:
      • Files/Exports: PascalCase (Button.tsx).
      • Styles: lowercase-hyphen (button.module.less).
      • CSS Modules: kebab-case (.btn-primary).
      • Type Aliases: PascalCase (ButtonSize).
    import React from 'react';
    import styles from './component.module.less';
    
    export type FooSize = 'small' | 'middle' | 'large';
    
    export interface FooProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'color'> {
        /** 尺寸 */
        size?: FooSize;
        /** 禁用 */
        disabled?: boolean;
        children?: React.ReactNode;
    }
    
    export const Foo: React.FC<FooProps> = ({ size = 'middle', disabled = false, className, children, ...rest }) => {
        const classNames = [styles.foo, styles[`foo-${size}`], disabled && styles['foo-disabled'], className]
            .filter(Boolean)
            .join(' ');
    
        return (
            <div className={classNames} aria-disabled={disabled || undefined} {...rest}>
                {children}
            </div>
        );
    };
    
    Foo.displayName = 'Foo';
  10. Set up git pre-commit hooks for documentation enforcement

    main

    To prevent documentation drift from being committed, you can install pre-commit hooks. These hooks run the full npm run ci pipeline automatically during git commit. This ensures that any missing documentation or failing tests are caught locally before they reach the remote repository.

    Run the following command to install the hooks via the prepare lifecycle script:

    npm run setup:hooks