Skip to content

Commit

Permalink
feat(collection-row): create new component and replace slot usages (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusps authored Apr 30, 2024
2 parents 2420b7b + b3f95a3 commit 176110c
Show file tree
Hide file tree
Showing 16 changed files with 279 additions and 227 deletions.
52 changes: 52 additions & 0 deletions packages/components/src/collection/collection-row.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Compose } from '@vtex/shoreline-primitives'
import { forwardRef, style } from '@vtex/shoreline-utils'
import type { ComponentPropsWithoutRef } from 'react'
import React from 'react'
import type { FlexOptions } from '../flex'

/**
* Row of the collection
* @status stable
*/
export const CollectionRow = forwardRef<HTMLDivElement, CollectionRowProps>(
function CollectionRow(props, ref) {
const {
asChild = false,
style: styleProp,
gap = '$space-2',
align = 'center',
justify = 'space-between',
direction = 'row',
...otherProps
} = props

const Comp = asChild ? Compose : 'div'

return (
<Comp
data-sl-collection-row
style={style({
'--gap': gap,
'--align': align,
'--justify': justify,
'--direction': direction,
...styleProp,
})}
ref={ref}
{...otherProps}
/>
)
}
)

export interface CollectionRowOptions
extends Pick<FlexOptions, 'gap' | 'align' | 'justify' | 'direction'> {
/**
* Children composition
* @default false
*/
asChild?: boolean
}

export type CollectionRowProps = CollectionRowOptions &
ComponentPropsWithoutRef<'div'>
20 changes: 10 additions & 10 deletions packages/components/src/collection/collection-view.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import type { ComponentPropsWithoutRef } from 'react'
import React, { forwardRef } from 'react'
import { Skeleton } from '../skeleton'
import {
EmptyState,
EmptyStateActions,
EmptyStateIllustration,
} from '../empty-state'
import {
IconMagnifyingGlass,
IconPlus,
IconPlusCircle,
IconProhibit,
IconWarningCircle,
} from '@vtex/shoreline-icons'
import { Heading } from '../heading'
import { createMessageHook } from '@vtex/shoreline-primitives'
import type { ComponentPropsWithoutRef } from 'react'
import React, { forwardRef } from 'react'
import { Button } from '../button'
import {
EmptyState,
EmptyStateActions,
EmptyStateIllustration,
} from '../empty-state'
import { Heading } from '../heading'
import { Skeleton } from '../skeleton'
import { Text } from '../text'
import { messages } from './messages'
import { createMessageHook } from '@vtex/shoreline-primitives'

const useMessage = createMessageHook(messages)

Expand Down
24 changes: 11 additions & 13 deletions packages/components/src/collection/collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ import React, { forwardRef } from 'react'
* @status stable
* @example
* <Collection>
* <Slot name="header">
* <Slot name="controls">
* <Search />
* <Pagination page={1} total={74} />
* </Slot>
* </Slot>
* <CollectionView status="ready">
* <div className="ready-view" />
* </CollectionView>
* <Slot name="footer">
* <Pagination page={1} total={74} />
* </Slot>
* </Collection>
* <CollectionRow>
* <Search />
* <Pagination page={1} total={74} />
* </CollectionRow>
* <CollectionView status="ready">
* <div className="ready-view" />
* </CollectionView>
* <CollectionRow align="flex-end">
* <Pagination page={1} total={74} />
* </Slot>
* </Collection>
*/
export const Collection = forwardRef<HTMLDivElement, CollectionProps>(
function Collection(props, ref) {
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/collection/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './collection'
export * from './collection-view'
export * from './collection-row'
Loading

0 comments on commit 176110c

Please sign in to comment.