npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gravity-ui/normalized-list

v0.1.0

Published

Normalized flat/tree list model and React list/select components

Readme

@gravity-ui/normalized-list

Core of the package is useNormalizedList: it takes list items in either a flat or tree shape and turns them into one normalized model — id-keyed data, hierarchy meta, visible order, and interactive state (selection, expansion, focus).

UI components (NormalizedList, NormalizedSelect, and the optional UIKit layer) sit on top of that model and stay customizable via render props.

Install

npm install @gravity-ui/normalized-list

Peer dependencies: react, react-dom. For @gravity-ui/normalized-list/uikit you need @gravity-ui/uikit, @gravity-ui/icons, and @floating-ui/react. Installing @gravity-ui/uikit is usually enough (it already depends on the other two). With strict package managers such as pnpm, install @gravity-ui/icons and @floating-ui/react explicitly if they do not resolve.

Migrating from @gravity-ui/uikit/unstable (TreeSelect, TreeList, useList)? See MIGRATION.md.

Idea

items (flat | tree)
        │
        ▼
  useNormalizedList
        │
        ├─ structure  → itemsById, groupsState, visibleFlattenIds, …
        └─ state      → selectedById, expandedById, activeItemId, …
                │
                ▼
     NormalizedList / NormalizedSelect
     (or your own view / UIKitNormalized*)

What the hook solves:

  • one API for flat and tree authoring formats;
  • O(1) access by id after normalize;
  • selection / expand / keyboard-friendly visible order (visibleFlattenIds);
  • UI stays dumb: pass list in and customize rendering.

Two input shapes

Payload T is yours. The list contract is only the node wrapper:

Flattened — item is T itself (optional id / selected / disabled):

import type {ListItemType} from '@gravity-ui/normalized-list';

const flat: ListItemType<string>[] = ['one', 'two', 'three'];

const flatObjects: ListItemType<{title: string}>[] = [
  {title: 'one'},
  {title: 'two', selected: true},
];

Tree — item has data: T and optional children:

const tree: ListItemType<{title: string}>[] = [
  {
    data: {title: 'Fruits'},
    children: [{data: {title: 'Apple'}}, {data: {title: 'Orange'}}],
  },
];

Both normalize into the same structure + state.

Package layout

| Entry | Import | What you get | | ----- | ----------------------------------- | ----------------------------------------------------------------------------------- | | Core | @gravity-ui/normalized-list | useNormalizedList, NormalizedList, NormalizedSelect, headless building blocks | | UIKit | @gravity-ui/normalized-list/uikit | UIKitNormalizedList, UIKitNormalizedSelect, themed item/control views |

Core ships a minimal fallback UI when you omit render props. For production, pass your own renderers or use the UIKit entry.

Quick start

1. Hook only

import {useNormalizedList} from '@gravity-ui/normalized-list';

const list = useNormalizedList({
  items: ['one', 'two', 'three'],
  getItemId: (item) => item,
});

// list.structure.itemsById
// list.structure.visibleFlattenIds
// list.state.selectedById / setSelected / …

2. List UI on top of the hook

Core NormalizedList / NormalizedSelect are supplied with fallback views for demos and exploration. For production, prefer your own UI that matches your design system — see Customizable views.

import {NormalizedList, useNormalizedList} from '@gravity-ui/normalized-list';

const items = [{data: {title: 'Parent'}, children: [{data: {title: 'Child'}}]}];

export function Example() {
  const list = useNormalizedList({items, defaultExpandedState: 'expanded'});

  return <NormalizedList list={list} multiple mapItemDataToContentProps={(item) => item} />;
}

3. UIKit preset

The uikit entry is a set of presets for @gravity-ui/uikit: themed defaults for list rows, select control, and popup. They address the “bring your own view” gap from §2 for that one case — you still can override via render props.

import {useNormalizedList} from '@gravity-ui/normalized-list';
import {UIKitNormalizedList} from '@gravity-ui/normalized-list/uikit';

export function Example() {
  const list = useNormalizedList({
    items: ['one', 'two', 'three'],
    getItemId: (item) => item,
  });

  return (
    <UIKitNormalizedList list={list} multiple mapItemDataToContentProps={(title) => ({title})} />
  );
}

NormalizedSelect / UIKitNormalizedSelect use the same model inside (items → normalize → list in a popup).

Customizable views

Override presentation without rewriting list logic:

  • NormalizedList / NormalizedSelect: renderItem, renderContainer
  • NormalizedSelect: also renderControl, renderPopup, renderError, slots slotBeforeListBody / slotAfterListBody
  • UIKit: swap defaults (UIKitListItemView in renderItem, UIKitNormalizedSelectControl, …) the same way
<NormalizedList
  list={list}
  mapItemDataToContentProps={(item) => item}
  renderItem={({id, props, context, renderContainerProps}) => (
    <MyRow {...props} {...renderContainerProps} isLast={context.isLastItem} />
  )}
  renderContainer={(containerProps) => <VirtualizedContainer {...containerProps} />}
/>

CSS namespace

BEM roots and package CSS variables use the g-nl- prefix (for example --g-nl-list-item-background-hover).

The UIKit entry maps those variables to @gravity-ui/uikit tokens (--g-color-*, --g-spacing-*, …).

Storybook

Examples live under normalized-list (core) and normalized-list/UIKit. Docs are *Docs.md next to each Storybook entry.

License

MIT