Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/mosaic-icon-stylex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
11 changes: 8 additions & 3 deletions packages/swingset/src/stories/icon.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import * as IconStories from './icon.stories';

# Icon

Icon renders a named glyph from Mosaic's icon set. It sizes through the `size` variant and inherits color from `currentColor`. Any glyph can be swapped per name through `appearance.icons` on `MosaicProvider`. Mosaic's styling applies to an override just like the built-in glyph — so swapped icons stay visually consistent — and the override also receives `data-cl-slot="icon"` for targeting.
Icon renders a named glyph from Mosaic's icon set. It sizes through the `size` variant and inherits color from `currentColor`. Any glyph can be swapped per name through `appearance.icons` on `MosaicProvider`. Mosaic's styling applies to an override just like the built-in glyph — so swapped icons stay visually consistent — and the override also carries the `.cl-icon` class and `data-size` attribute for targeting.

Set `placement` when the icon sits beside text inside a container. It adds no styling of its own; it reflects `data-icon="inline-start"` or `data-icon="inline-end"` so the container can react — a `Button`, for example, tightens its padding on the side the icon sits with `:has([data-icon='inline-end'])`. The values are the CSS logical directions, so they follow the writing mode rather than naming a physical edge. Leave it unset for a standalone icon.

## Playground

Expand All @@ -15,7 +17,10 @@ Icon renders a named glyph from Mosaic's icon set. It sizes through the `size` v

<PropTable
meta={IconStories.meta}
extra={[{ name: 'name', type: 'IconName' }]}
extra={[
{ name: 'name', type: 'IconName' },
{ name: 'placement', type: "'inline-start' | 'inline-end'" },
]}
/>

## Usage
Expand Down Expand Up @@ -46,7 +51,7 @@ Icon renders a named glyph from Mosaic's icon set. It sizes through the `size` v

### Overriding a glyph

Pass `appearance.icons` to `MosaicProvider` to replace a glyph by name. The override is a function receiving the resolved props — Mosaic's sizing/color `className` and `data-cl-slot` — which you spread onto your own element. Because Mosaic's styling applies to the override too, the replacement only supplies its `viewBox` and paths.
Pass `appearance.icons` to `MosaicProvider` to replace a glyph by name. The override is a plain element; Mosaic clones it with the resolved sizing `className` and `data-size`, keeping any class the element already had. The replacement only supplies its `viewBox` and paths.

<Story
name='Override'
Expand Down
18 changes: 13 additions & 5 deletions packages/swingset/src/stories/icon.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @jsxImportSource @emotion/react */
import type { IconProps } from '@clerk/ui/mosaic/components/icon';
import { Icon, iconRecipe } from '@clerk/ui/mosaic/components/icon';
import { Icon } from '@clerk/ui/mosaic/components/icon';
import { iconRegistry } from '@clerk/ui/mosaic/icons/registry';
import { MosaicProvider } from '@clerk/ui/mosaic/MosaicProvider';

Expand All @@ -13,8 +13,16 @@ export { default as __source } from './icon.stories?raw';
export const meta: StoryMeta = {
group: 'Components',
title: 'Icon',
source: 'packages/ui/src/mosaic/components/icon.tsx',
styles: iconRecipe,
source: 'packages/ui/src/mosaic/components/icon/icon.tsx',
styleEngine: 'stylex',
styles: {
_variants: {
size: { sm: {}, md: {}, lg: {} },
},
_defaultVariants: {
size: 'md',
},
},
};

// Story functions accept Record<string,unknown> (knob values) and cast to IconProps.
Expand Down Expand Up @@ -78,8 +86,8 @@ export function Override() {
return (
<MosaicProvider
appearance={{
// Overrides are elements now, not render functions: Mosaic injects its sizing className and
// `data-cl-slot` into the element via cloneElement, so the replacement only needs its viewBox
// Overrides are elements, not render functions: Mosaic injects its sizing className and
// `data-size` into the element via cloneElement, so the replacement only needs its viewBox
// + paths. Passing an element (vs a function) also lets overrides be supplied from a Server
// Component, since elements serialize across the RSC boundary.
icons: {
Expand Down
105 changes: 0 additions & 105 deletions packages/ui/src/mosaic/__tests__/icon.test.tsx

This file was deleted.

81 changes: 0 additions & 81 deletions packages/ui/src/mosaic/components/icon.tsx

This file was deleted.

13 changes: 13 additions & 0 deletions packages/ui/src/mosaic/components/icon/icon.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as stylex from '@stylexjs/stylex';

import { space } from '../../tokens.stylex';

export const styles = stylex.create({
base: { display: 'inline-block', flexShrink: 0 },
});

export const sizes = stylex.create({
sm: { height: space['3.5'], width: space['3.5'] },
md: { height: space['4'], width: space['4'] },
lg: { height: space['5'], width: space['5'] },
});
Loading
Loading