op-ent / unstyled-ui

https://github.com/op-ent/op-ent/tree/main/packages/shared-ui
MIT License
6 stars 1 forks source link
headless mit react typescript

Banner

@op-ent/unstyled-ui

npm version npm downloads Github Actions bundle Codecov MIT License

@op-ent/unstyled-ui is an headless react library.

Motivation

When it comes to components libaries, there are two main approaches:

So here comes unstyled-ui, whose purpose is to conciliate both approaches :

Usage

Install package:

# npm
npm install @op-ent/unstyled-ui

# yarn
yarn install @op-ent/unstyled-ui

# pnpm
pnpm install @op-ent/unstyled-ui

Import example:

// ESM
import { Button } from '@op-ent/unstyled-ui'

// CommonJS
const { Button } = require('@op-ent/unstyled-ui')

Create a config

// lib/config.ts
import { createConfig } from '@op-ent/unstyled-ui'

declare module '@op-ent/unstyled-ui' {
    interface CustomizableComponentsPropsOverride {
        button: {
            variant: 'primary' | 'secondary'
        }
    }
}

export const { config, extendConfig } = createConfig({
    components: {
        button: {
            defaultProps: {
                variant: 'secondary',
            },
            customProps: ['variant'],
        },
    },
})

Use the config

import { ConfigProvider } from '@op-ent/unstyled-ui'
import { config } from '~/lib/config'

function App() {
    return (
        <ConfigProvider config={config}>
            <Button variant="primary">Hello world</Button>
        </ConfigProvider>
    )
}

Styling

Using CSS data parts:

.uui-button[data-part='root'] {
}
.uui-button[data-part='loader'] {
}
.uui-button[data-part='left-icon'] {
}
.uui-button[data-part='right-icon'] {
}
.uui-button[data-part='children'] {
}
.uui-button[data-part='loading-text'] {
}

Planned components & features

WARNING: This is a work in progress.

  • This list is not complete and may change at any time.
  • Names may change in the future.

API Reference

TBD

💻 Development

Inspiration

License

Published under MIT License.

Made with ❤️ by Florian LEFEBVRE in France.


Sponsors
Netlify banner Cleavr banner