Skip to content

Commit

Permalink
Merge branch 'main' into empty-state-props
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm authored Oct 18, 2024
2 parents 3b2888e + 1bcf8e1 commit 4276145
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 97 deletions.
8 changes: 5 additions & 3 deletions src/components/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,11 @@ export function DynamicBreadcrumbs({

const refitCrumbList = useCallback(
({ width: wrapperWidth }: { width: number }) => {
const lists = Array.from(
wrapperRef?.current?.querySelectorAll(`[${CRUMB_LIST_ATTR}]`)
)
const lists = wrapperRef?.current
? Array.from(
wrapperRef.current.querySelectorAll(`[${CRUMB_LIST_ATTR}]`)
)
: []
const { id } = lists.reduce(
(prev, next) => {
const prevWidth = prev.width
Expand Down
79 changes: 58 additions & 21 deletions src/components/Flex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
forwardRef,
memo,
} from 'react'
import { useTheme } from 'styled-components'
import styled, { type DefaultTheme } from 'styled-components'

type FlexBaseProps = {
/**
Expand Down Expand Up @@ -45,15 +45,15 @@ type FlexBaseProps = {
| 'space-around'
| 'space-evenly'

gap?: string

gap?: keyof DefaultTheme['spacing']
padding?: keyof DefaultTheme['spacing']
children?: ReactNode
}

type FlexProps = Omit<CSSProperties, keyof FlexBaseProps> & FlexBaseProps

function FlexRef(props: FlexProps, ref: Ref<any>) {
const {
function FlexRef(
{
direction,
wrap,
basis,
Expand All @@ -62,32 +62,69 @@ function FlexRef(props: FlexProps, ref: Ref<any>) {
align,
justify,
gap,
padding,
children,
...otherProps
} = props
const theme = useTheme()

}: FlexProps,
ref: Ref<any>
) {
return (
<div
<FlexSC
ref={ref}
style={{
display: 'flex',
flexDirection: direction,
flexWrap: typeof wrap === 'boolean' ? 'wrap' : wrap,
flexBasis: basis,
flexGrow: typeof grow === 'boolean' ? 1 : grow,
flexShrink: typeof shrink === 'boolean' ? 1 : shrink,
alignItems: align,
justifyContent: justify,
gap: (theme.spacing as any)[gap] || 0,
...otherProps,
{...{
$direction: direction,
$wrap: wrap,
$basis: basis,
$grow: grow,
$shrink: shrink,
$align: align,
$justify: justify,
$gap: gap,
$padding: padding,
}}
style={{ ...otherProps }}
>
{children}
</div>
</FlexSC>
)
}

const FlexSC = styled.div<{
$direction?: FlexProps['direction']
$wrap?: FlexProps['wrap']
$basis?: FlexProps['basis']
$grow?: FlexProps['grow']
$shrink?: FlexProps['shrink']
$align?: FlexProps['align']
$justify?: FlexProps['justify']
$gap?: FlexProps['gap']
$padding?: FlexProps['padding']
}>(
({
theme,
$direction,
$wrap,
$basis,
$grow,
$shrink,
$align,
$justify,
$gap,
$padding,
}) => ({
display: 'flex',
flexDirection: $direction,
flexWrap: typeof $wrap === 'boolean' ? 'wrap' : $wrap,
flexBasis: $basis,
flexGrow: typeof $grow === 'boolean' ? 1 : $grow,
flexShrink: typeof $shrink === 'boolean' ? 1 : $shrink,
alignItems: $align,
justifyContent: $justify,
gap: theme.spacing[$gap] || 0,
padding: theme.spacing[$padding] || 0,
})
)

const BaseFlex = forwardRef(FlexRef)

const Flex = memo(BaseFlex)
Expand Down
2 changes: 1 addition & 1 deletion src/components/Layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const LayerWrapper = styled.div<{
$margin: SimpleMarginType
}>(({ $position, $margin }) => ({
display: 'flex',
$position: 'absolute',
position: 'absolute',
pointerEvents: 'none',
'& > *': {
pointerEvents: 'auto',
Expand Down
131 changes: 76 additions & 55 deletions src/components/RepositoryCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Div, type DivProps, Flex, H1, H3, P, Span } from 'honorable'
import {
type ComponentProps,
type ReactNode,
Expand All @@ -11,12 +10,13 @@ import styled, { useTheme } from 'styled-components'
import Chip from './Chip'
import PadlockLockedIcon from './icons/PadlockLockedIcon'
import VerifiedIcon from './icons/VerifiedIcon'
import Card from './Card'
import Card, { type CardProps } from './Card'
import RocketIcon from './icons/RocketIcon'

import AppIcon from './AppIcon'
import Flex from './Flex'

type RepositoryCardProps = DivProps & {
type RepositoryCardProps = CardProps & {
title?: string
publisher?: string
priv?: boolean
Expand Down Expand Up @@ -107,15 +107,17 @@ function RepositoryCardRef(
<Card
ref={ref}
clickable
flexDirection="column"
paddingTop={
featuredLabel ? theme.spacing.large + theme.spacing.medium : 'large'
}
paddingRight="large"
paddingBottom="large"
paddingLeft="large"
width="100%"
position="relative"
style={{
flexDirection: 'column',
paddingTop: featuredLabel
? theme.spacing.large + theme.spacing.medium
: theme.spacing.large,
paddingRight: theme.spacing.large,
paddingBottom: theme.spacing.large,
paddingLeft: theme.spacing.large,
width: '100%',
position: 'relative',
}}
{...props}
>
{featuredLabel && <FeaturedBorder>{featuredLabel}</FeaturedBorder>}
Expand Down Expand Up @@ -144,21 +146,16 @@ function RepositoryCardRef(
)}
<Flex
direction="row"
marginLeft={size === 'small' ? 'small' : 0}
marginLeft={size === 'small' ? theme.spacing.small : 0}
width="100%"
align="flex-start"
justify="space-between"
>
<Flex direction="column">
<H1
color="text"
{...(variant === 'marketing'
? featuredLabel
? { title2: true }
: { subtitle1: true }
: size === 'large'
? { title1: true }
: { title2: true })}
<HeaderSC
$variant={variant}
$featuredLabel={!!featuredLabel}
$size={size}
>
{title}
{!!verified && (
Expand All @@ -170,22 +167,19 @@ function RepositoryCardRef(
left={4}
/>
)}
</H1>
<H3
body2
{...(variant === 'marketing' && !featuredLabel
? { caption: true }
: { body2: true })}
color="text-xlight"
marginBottom={size === 'large' ? 'small' : 0}
</HeaderSC>
<SubheaderSC
$variant={variant}
$featuredLabel={!!featuredLabel}
$size={size}
>
{publisher}
</H3>
</SubheaderSC>
</Flex>
<Flex
justifyContent="end"
flexGrow={1}
marginLeft="medium"
marginLeft={theme.spacing.medium}
gap="small"
alignItems="center"
>
Expand All @@ -209,25 +203,11 @@ function RepositoryCardRef(
</Flex>
</Flex>
</Flex>
{description && (
<P
body2
marginTop="xsmall"
color="text-light"
style={{
display: '-webkit-box',
WebkitLineClamp: '2',
WebkitBoxOrient: 'vertical',
overflow: 'hidden',
}}
>
{description}
</P>
)}
<Div flexGrow={1} />
{description && <DescriptionSC>{description}</DescriptionSC>}
<div style={{ flexGrow: 1 }} />
{(trending || tags?.length > 0) && (
<Flex
marginTop="medium"
marginTop={theme.spacing.medium}
gap="xsmall"
flexWrap="wrap"
>
Expand All @@ -237,12 +217,7 @@ function RepositoryCardRef(
hue="lighter"
>
<RocketIcon color="action-link-inline" />
<Span
color="action-link-inline"
marginLeft="xxsmall"
>
Trending
</Span>
<SpanSC>Trending</SpanSC>
</Chip>
)}
{tags
Expand All @@ -265,6 +240,52 @@ function RepositoryCardRef(
)
}

const HeaderSC = styled.h1<{
$variant?: RepositoryCardProps['variant']
$featuredLabel?: boolean
$size?: RepositoryCardProps['size']
}>(({ theme, $variant, $featuredLabel, $size }) => ({
margin: 0,
color: theme.colors.text,
...($variant === 'marketing'
? $featuredLabel
? { ...theme.partials.text.title2 }
: { ...theme.partials.text.subtitle1 }
: $size === 'large'
? { ...theme.partials.text.title1 }
: { ...theme.partials.text.title2 }),
}))

const SubheaderSC = styled.h3<{
$variant?: RepositoryCardProps['variant']
$featuredLabel?: boolean
$size?: RepositoryCardProps['size']
}>(({ theme, $variant, $featuredLabel, $size }) => ({
margin: 0,
...theme.partials.text.body2,
color: theme.colors['text-xlight'],
marginBottom: $size === 'large' ? theme.spacing.small : 0,
...($variant === 'marketing' && !$featuredLabel
? { ...theme.partials.text.caption }
: {}),
}))

const SpanSC = styled.span(({ theme }) => ({
color: theme.colors['action-link-inline'],
marginLeft: theme.spacing.xxsmall,
}))

const DescriptionSC = styled.p(({ theme }) => ({
...theme.partials.text.body2,
margin: 0,
marginTop: theme.spacing.xsmall,
color: theme.colors['text-light'],
display: '-webkit-box',
WebkitLineClamp: '2',
WebkitBoxOrient: 'vertical',
overflow: 'hidden',
}))

const RepositoryCard = forwardRef(RepositoryCardRef)

export default RepositoryCard
10 changes: 5 additions & 5 deletions src/components/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ export type SelectProps = Exclude<SelectButtonProps, 'children'> & {
type TriggerProps = {
buttonRef: RefObject<HTMLElement>
buttonElt: any
$isOpen: boolean
isOpen: boolean
} & HTMLAttributes<HTMLElement>

function Trigger({ buttonElt, $isOpen, ...props }: TriggerProps) {
function Trigger({ buttonElt, isOpen, ...props }: TriggerProps) {
const ref = props.buttonRef
const { buttonProps } = useButton(props, ref)
const theme = useTheme()
Expand All @@ -90,10 +90,10 @@ function Trigger({ buttonElt, $isOpen, ...props }: TriggerProps) {
ref,
...buttonProps,
...(buttonElt?.props?.type ? { type: buttonElt.props.type } : {}),
$isOpen,
isOpen,
style: {
appearance: 'unset',
...($isOpen ? { zIndex: theme.zIndexes.tooltip + 1 } : {}),
...(isOpen ? { zIndex: theme.zIndexes.tooltip + 1 } : {}),
},
tabIndex: 0,
})
Expand Down Expand Up @@ -374,7 +374,7 @@ function Select({
<Trigger
buttonRef={triggerRef as unknown as RefObject<HTMLElement>}
buttonElt={triggerButton}
$isOpen={state.isOpen}
isOpen={state.isOpen}
{...triggerProps}
/>
<PopoverListBox
Expand Down
4 changes: 2 additions & 2 deletions src/components/TabList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const TabClone = styled(
ref: tabRef,
...props,
})
)<{ $vertical: boolean }>(({ theme, $vertical: vertical }) => ({
)<{ vertical: boolean }>(({ theme, vertical }) => ({
position: 'relative',
'&:focus, &:focus-visible': {
outline: 'none',
Expand Down Expand Up @@ -244,7 +244,7 @@ function TabRenderer({ item, state, stateProps, stateRef }: TabRendererProps) {
tabRef={ref}
{...props}
active={state.selectedKey === item.key}
$vertical={stateProps.orientation === 'vertical'}
vertical={stateProps.orientation === 'vertical'}
{...item.props}
>
{item.rendered}
Expand Down
Loading

0 comments on commit 4276145

Please sign in to comment.