Repository navigation
feat(mosaic): add an Entity component for the members table #10186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import * as stylex from '@stylexjs/stylex'; | ||
|
|
||
| import { colorVars, fontFamilyVars, fontWeightVars, space, typeScaleVars } from '../../tokens.stylex'; | ||
|
|
||
| export const entity = stylex.create({ | ||
| base: { | ||
| gap: space['2'], | ||
| alignItems: 'center', | ||
| display: 'flex', | ||
| fontFamily: fontFamilyVars['--cl-font-family-sans'], | ||
| minWidth: 0, | ||
| }, | ||
| }); | ||
|
|
||
| export const media = stylex.create({ | ||
| base: { | ||
| alignItems: 'center', | ||
| aspectRatio: '1/1', | ||
| display: 'flex', | ||
| flexShrink: 0, | ||
| justifyContent: 'center', | ||
| width: space['9.5'], | ||
| }, | ||
| }); | ||
|
|
||
| export const content = stylex.create({ | ||
| base: { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| flexGrow: 1, | ||
| minWidth: 0, | ||
| }, | ||
| }); | ||
|
|
||
| export const label = stylex.create({ | ||
| base: { | ||
| gap: space['2'], | ||
| alignItems: 'center', | ||
| color: colorVars['--cl-color-foreground'], | ||
| display: 'flex', | ||
| fontSize: typeScaleVars['--cl-text-sm-size'], | ||
| fontWeight: fontWeightVars['--cl-font-medium'], | ||
| lineHeight: typeScaleVars['--cl-text-sm-leading'], | ||
| minWidth: 0, | ||
| }, | ||
| }); | ||
|
|
||
| export const description = stylex.create({ | ||
| base: { | ||
| color: colorVars['--cl-color-foreground-secondary'], | ||
| fontSize: typeScaleVars['--cl-text-xs-size'], | ||
| fontWeight: fontWeightVars['--cl-font-normal'], | ||
| lineHeight: typeScaleVars['--cl-text-xs-leading'], | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import * as stylex from '@stylexjs/stylex'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import React from 'react'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { Entity } from './entity'; | ||
|
|
||
| const overrides = stylex.create({ | ||
| root: { marginTop: '8px' }, | ||
| }); | ||
|
|
||
| const atoms = (style: stylex.StyleXStyles) => | ||
| (stylex.props(style).className ?? '').split(' ').filter(name => /^x[a-z0-9]+$/.test(name)); | ||
|
|
||
| describe('Mosaic Entity', () => { | ||
| it('renders the composed parts with their stable classes', () => { | ||
| render( | ||
| <Entity.Root data-testid='root'> | ||
| <Entity.Media data-testid='media'> | ||
| <span>avatar</span> | ||
| </Entity.Media> | ||
| <Entity.Content data-testid='content'> | ||
| <Entity.Label data-testid='label'>Cameron Walker</Entity.Label> | ||
| <Entity.Description>cameron@clerk.com</Entity.Description> | ||
| </Entity.Content> | ||
| </Entity.Root>, | ||
| ); | ||
| expect(screen.getByTestId('root')).toHaveClass('cl-entity'); | ||
| expect(screen.getByTestId('media')).toHaveClass('cl-entity-media'); | ||
| expect(screen.getByTestId('content')).toHaveClass('cl-entity-content'); | ||
| expect(screen.getByTestId('label')).toHaveClass('cl-entity-label'); | ||
| expect(screen.getByText('cameron@clerk.com')).toHaveClass('cl-entity-description'); | ||
| }); | ||
|
|
||
| it('gives the label text its own box to truncate, leaving a badge beside it whole', () => { | ||
| render( | ||
| <Entity.Label data-testid='label'> | ||
| Cameron Walker | ||
| <span>Default</span> | ||
| </Entity.Label>, | ||
| ); | ||
| const label = screen.getByTestId('label'); | ||
| expect(screen.getByText('Cameron Walker')).not.toBe(label); | ||
| expect(screen.getByText('Cameron Walker').parentElement).toBe(label); | ||
| expect(screen.getByText('Default').parentElement).toBe(label); | ||
| }); | ||
|
|
||
| it('applies xstyle to the root element', () => { | ||
| render(<Entity.Root xstyle={overrides.root}>Hi</Entity.Root>); | ||
| expect(screen.getByText('Hi')).toHaveClass('cl-entity', ...atoms(overrides.root)); | ||
| }); | ||
|
|
||
| it('merges a render-sourced className instead of clobbering its own', () => { | ||
| render(<Entity.Content render={<Entity.Description />}>Hi</Entity.Content>); | ||
| expect(screen.getByText('Hi')).toHaveClass('cl-entity-content', 'cl-entity-description'); | ||
| }); | ||
|
|
||
| it('forwards the ref to the root element', () => { | ||
| const ref = React.createRef<HTMLDivElement>(); | ||
| render(<Entity.Root ref={ref}>Hi</Entity.Root>); | ||
| expect(ref.current).toBe(screen.getByText('Hi')); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import * as stylex from '@stylexjs/stylex'; | ||
| import React from 'react'; | ||
|
|
||
| import { useRender } from '../../primitives/utils'; | ||
| import type { MosaicComponentProps } from '../../props'; | ||
| import { mergeStyleProps, themeProps } from '../../props'; | ||
| import { reset } from '../../styles/reset.styles'; | ||
| import { truncationStyles } from '../../styles/typography.styles'; | ||
| import { withTruncatableLabel } from '../../utils/truncatable-label'; | ||
| import * as slots from './entity.styles'; | ||
|
|
||
| const Root = React.forwardRef<HTMLDivElement, MosaicComponentProps<'div'>>(function MosaicEntity( | ||
|
alexcarpenter marked this conversation as resolved.
|
||
| { render, xstyle, ...rest }, | ||
| ref, | ||
| ) { | ||
| return useRender({ | ||
| defaultTagName: 'div', | ||
| render, | ||
| ref, | ||
| props: { | ||
| ...mergeStyleProps(themeProps('entity'), stylex.props(reset.base, slots.entity.base, xstyle), rest), | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| const Media = React.forwardRef<HTMLDivElement, MosaicComponentProps<'div'>>(function MosaicEntityMedia( | ||
| { render, xstyle, ...rest }, | ||
| ref, | ||
| ) { | ||
| return useRender({ | ||
| defaultTagName: 'div', | ||
| render, | ||
| ref, | ||
| props: { | ||
| ...mergeStyleProps(themeProps('entity-media'), stylex.props(reset.base, slots.media.base, xstyle), rest), | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| const Content = React.forwardRef<HTMLDivElement, MosaicComponentProps<'div'>>(function MosaicEntityContent( | ||
| { render, xstyle, ...rest }, | ||
| ref, | ||
| ) { | ||
| return useRender({ | ||
| defaultTagName: 'div', | ||
| render, | ||
| ref, | ||
| props: { | ||
| ...mergeStyleProps(themeProps('entity-content'), stylex.props(reset.base, slots.content.base, xstyle), rest), | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| const Label = React.forwardRef<HTMLDivElement, MosaicComponentProps<'div'>>(function MosaicEntityLabel( | ||
| { children, render, xstyle, ...rest }, | ||
| ref, | ||
| ) { | ||
| return useRender({ | ||
| defaultTagName: 'div', | ||
| render, | ||
| ref, | ||
| props: { | ||
| ...mergeStyleProps(themeProps('entity-label'), stylex.props(reset.base, slots.label.base, xstyle), rest), | ||
| children: withTruncatableLabel(children), | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| const Description = React.forwardRef<HTMLDivElement, MosaicComponentProps<'div'>>(function MosaicEntityDescription( | ||
| { render, xstyle, ...rest }, | ||
| ref, | ||
| ) { | ||
| return useRender({ | ||
| defaultTagName: 'div', | ||
| render, | ||
| ref, | ||
| props: { | ||
| ...mergeStyleProps( | ||
| themeProps('entity-description'), | ||
| stylex.props(reset.base, slots.description.base, truncationStyles.singleLine, xstyle), | ||
| rest, | ||
| ), | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| export const Entity = { | ||
| Root, | ||
| Media, | ||
| Content, | ||
| Label, | ||
| Description, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { Entity } from './entity'; |
3 changes: 0 additions & 3 deletions
3
packages/mosaic/src/features/organization-profile/members-table-tab.styles.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,5 @@ | ||
| import * as stylex from '@stylexjs/stylex'; | ||
|
|
||
| import { space } from '../../tokens.stylex'; | ||
|
|
||
| export const styles = stylex.create({ | ||
| deprovisionedRow: { opacity: 0.5 }, | ||
| name: { gap: space['2'], alignItems: 'center', display: 'flex' }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.