Skip to content

Commit

Permalink
chore(): Update typings (#1502)
Browse files Browse the repository at this point in the history
  • Loading branch information
huzefakagdi committed Jul 8, 2024
1 parent e345d54 commit e760968
Show file tree
Hide file tree
Showing 31 changed files with 117 additions and 148 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "pcln-design-system",
"comment": "Update typings for several components",
"type": "minor"
}
],
"packageName": "pcln-design-system"
}
4 changes: 2 additions & 2 deletions packages/core/src/BackgroundImage/BackgroundImage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { type ComponentPropsWithoutRef } from 'react'
import styled, { css } from 'styled-components'
import {
BorderRadiusProps,
Expand Down Expand Up @@ -33,7 +33,7 @@ const image = (props) => (props.image ? { backgroundImage: `url(${props.image})`
export type BackgroundImageProps = WidthProps &
HeightProps &
BorderRadiusProps &
Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'width' | 'height'> & {
Omit<ComponentPropsWithoutRef<'img'>, 'width' | 'height'> & {
variation?: 'parallax' | 'static'
image?: string
borderRadius?: string
Expand Down
40 changes: 18 additions & 22 deletions packages/core/src/Box/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { MutableRefObject } from 'react'
import React, { type ComponentPropsWithRef } from 'react'
import styled from 'styled-components'
import {
BorderRadiusProps,
Expand All @@ -10,6 +10,7 @@ import {
MinHeightProps,
MinWidthProps,
OverflowProps,
type ResponsiveValue,
SizeProps,
SpaceProps,
TextAlignProps,
Expand All @@ -29,15 +30,15 @@ import {
textAlign,
width,
} from 'styled-system'
import type { ColorSchemeName } from '../theme/theme'
import type { BorderRadius, BoxShadowSize, ColorSchemeName } from '../theme/theme'
import { borderRadiusAttrs } from '../utils/attrs/borderRadiusAttrs'
import { boxShadowAttrs } from '../utils/attrs/boxShadowAttrs'
import { applyVariations, color, colorScheme } from '../utils/utils'

/**
* @public
*/
export type BoxProps = BorderRadiusProps &
export type BoxProps = Omit<BorderRadiusProps, 'borderRadius'> &
BoxShadowProps &
DisplayProps &
HeightProps &
Expand All @@ -50,27 +51,15 @@ export type BoxProps = BorderRadiusProps &
SpaceProps &
TextAlignProps &
WidthProps &
React.HTMLAttributes<HTMLDivElement> & {
children?: React.ReactNode | string
ComponentPropsWithRef<'div'> & {
children?: React.ReactNode
as?: unknown
role?: string
bg?: string
color?: string
className?: string
borderRadiusSize?:
| 'none'
| 'xsm'
| 'sm'
| 'md'
| 'lg'
| 'xl'
| '2xl'
| '3xl'
| 'full'
| 'action-sm'
| 'action-md'
| 'action-lg'
boxShadowSize?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'overlay-lg' | 'overlay-xl'
borderRadius?: ResponsiveValue<BorderRadius> | BorderRadiusProps['borderRadius']
boxShadowSize?: ResponsiveValue<BoxShadowSize>
boxShadowColor?:
| 'primary'
| 'secondary'
Expand All @@ -89,9 +78,16 @@ export type BoxProps = BorderRadiusProps &
| 'border'
| 'background'
colorScheme?: ColorSchemeName
onClick?: (unknown) => unknown
ref?: MutableRefObject<HTMLDivElement>
rounded?: 'top' | 'right' | 'bottom' | 'left' | 'topLeft' | 'topRight' | 'bottomRight' | 'bottomLeft'
rounded?:
| 'round'
| 'top'
| 'right'
| 'bottom'
| 'left'
| 'topLeft'
| 'topRight'
| 'bottomRight'
| 'bottomLeft'
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/Breadcrumbs/BreadcrumbLink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { Flex } from '../Flex/Flex'
import { Link } from '../Link/Link'
import { Link, LinkProps } from '../Link/Link'
import { Text } from '../Text/Text'

/**
Expand All @@ -12,13 +12,13 @@ export type BreadcrumbLinkProps = React.RefAttributes<unknown> & {
href?: string
icon?: React.ReactNode
label?: string
onClick?: (unknown) => unknown
onClick?: LinkProps['onClick']
}

/**
* @public
*/
export const BreadcrumbLink: React.FC<BreadcrumbLinkProps> = React.forwardRef(
export const BreadcrumbLink: React.FC<BreadcrumbLinkProps> = React.forwardRef<HTMLAnchorElement, BreadcrumbLinkProps>(
({ className, isLastChild, href, icon, label, onClick }, ref) => {
const linkColor = isLastChild ? 'text.dark' : 'text.light'

Expand Down
6 changes: 1 addition & 5 deletions packages/core/src/Button/Button.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,7 @@ describe('Button', () => {

expect(button).toHaveStyleRule('border-radius', borderRadius['action-md'])

rerender(
<Button size='small' borderRadius=''>
BUTTON
</Button>
)
rerender(<Button size='small'>BUTTON</Button>)
expect(button).toHaveStyleRule('border-radius', borderRadius['action-sm'])

rerender(
Expand Down
20 changes: 9 additions & 11 deletions packages/core/src/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { themeGet } from '@styled-system/theme-get'
import React from 'react'
import React, { type ComponentPropsWithRef } from 'react'
import styled, { css } from 'styled-components'
import {
BoxShadowProps,
HeightProps,
type ResponsiveValue,
SpaceProps,
WidthProps,
borderRadius,
Expand All @@ -17,6 +18,7 @@ import {
import { Flex, type FlexProps } from '../Flex/Flex'
import { boxShadowAttrs } from '../utils/attrs/boxShadowAttrs'
import { applySizes, applyVariations, borders, getPaletteColor, getTextColorOn } from '../utils/utils'
import { type BorderRadius, type BoxShadowSize } from '../theme'

/**
* @public
Expand Down Expand Up @@ -213,20 +215,16 @@ export type ButtonProps = WidthProps &
HeightProps &
SpaceProps &
BoxShadowProps &
React.ButtonHTMLAttributes<HTMLButtonElement> &
React.RefAttributes<unknown> & {
ComponentPropsWithRef<'button'> & {
color?: string
variation?: ButtonVariations
size?: ButtonSizes | ButtonSizes[]
borderRadius?: 'none' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | 'full' | ''
boxShadowSize?: '' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'overlay-md' | 'overlay-lg' | 'overlay-xl'
borderRadius?: BorderRadius
boxShadowSize?: ResponsiveValue<BoxShadowSize>
autoFocus?: boolean
IconLeft?: React.Component
IconRight?: React.Component
IconLeft?: React.Component | React.FC
IconRight?: React.Component | React.FC
flexProps?: FlexProps
onClick?: (unknown) => unknown
onFocus?: (unknown) => unknown
onMouseEnter?: (unknown) => unknown
}

export const buttonStyles = css`
Expand Down Expand Up @@ -357,7 +355,7 @@ const ButtonIcon = ({ Component, ...props }) => {
/**
* @public
*/
export const Button = React.forwardRef((props: ButtonProps, ref) => {
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
const { children, ...restProps } = props
const { IconLeft, IconRight, size = 'medium', flexProps = {} } = props
const hasChildren = React.Children.toArray(children).length > 0
Expand Down
8 changes: 3 additions & 5 deletions packages/core/src/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BoxChecked, BoxEmpty, BoxMinus } from 'pcln-icons'
import React, { useEffect, useState } from 'react'
import React, { type ComponentPropsWithRef, useEffect, useState } from 'react'
import styled from 'styled-components'
import { applyVariations, getPaletteColor } from '../utils/utils'

Expand Down Expand Up @@ -100,16 +100,14 @@ const StyledInput = styled.input`
/**
* @public
*/
export type CheckboxProps = React.InputHTMLAttributes<HTMLInputElement> & {
id: string
export type CheckboxProps = ComponentPropsWithRef<'input'> & {
id?: string
indeterminate?: boolean
size?: number
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void
color?: string
checked?: boolean
defaultChecked?: boolean
disabled?: boolean
ref?: React.Ref<HTMLInputElement>
unselectedColor?: string
}

Expand Down
32 changes: 10 additions & 22 deletions packages/core/src/Chip/ButtonChip/ButtonChip.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { ChevronDown } from 'pcln-icons'
import React from 'react'
import styled from 'styled-components'
import { FontSizeProps, SpaceProps } from 'styled-system'
import { Button } from '../../Button/Button'
import { Button, type ButtonProps } from '../../Button/Button'
import { getPaletteColor } from '../../utils/utils'
import { ChipContent, type IconComponent } from '../ChipContent/ChipContent'
import { ChipContent, type ChipContentProps } from '../ChipContent/ChipContent'
import { ChipContentWrapper } from '../ChipContentWrapper'

const ChipButton = styled(Button)`
Expand Down Expand Up @@ -34,29 +33,18 @@ export type ButtonChipVariation = 'outline' | 'shadow'
/**
* @public
*/
export type ButtonChipProps = SpaceProps &
FontSizeProps & {
BridgeIcon?: IconComponent
bridgeLabel?: string
children?: React.ReactNode
color?: string
disabled?: boolean
expanded?: boolean
facet?: string
Icon?: IconComponent
id?: string
label?: string
selected?: boolean
showActionIcon?: boolean
onClick?: (unknown) => unknown
width?: string
variation?: ButtonChipVariation
}
export type ButtonChipProps = Omit<ChipContentProps, 'action' | 'ref'> & {
expanded?: boolean
id?: string
showActionIcon?: boolean
onClick?: ButtonProps['onClick']
variation?: ButtonChipVariation
}

/**
* @public
*/
export const ButtonChip: React.FC<ButtonChipProps> = React.forwardRef(
export const ButtonChip: React.FC<ButtonChipProps> = React.forwardRef<HTMLButtonElement, ButtonChipProps>(
(
{
color,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Chip/FilterChip/FilterChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type FilterChipProps = SpaceProps &
actionTitle?: string
value?: string | number
color?: string
children?: React.ReactNode | string
children?: React.ReactNode
variation?: FilterChipVariation
}

Expand Down
7 changes: 2 additions & 5 deletions packages/core/src/CloseButton/CloseButton.styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ import React from 'react'
import styled, { css } from 'styled-components'
import { ComposedStyleFns } from '../theme/theme'
import { getPaletteColor } from '../utils/utils'
import type { CloseButtonProps } from './CloseButton'
import { type MotionButtonProps } from './CloseButton'

/** @public */
export const closeButtonSizes = ['sm', 'md', 'lg'] as const

/** @public */
export type CloseButtonSize = (typeof closeButtonSizes)[number] | number

/** @public */
export type MotionButtonProps = HTMLMotionProps<'button'> & CloseButtonProps

export const closeButtonIconSizes: Record<CloseButtonSize, number> = {
sm: 20,
md: 24,
Expand All @@ -38,7 +35,7 @@ export const closeButtonVariants = ['filled', 'white'] as const
/** @public */
export type CloseButtonVariant = (typeof closeButtonVariants)[number]

export const closeButtonVariantProps: Record<CloseButtonVariant, Omit<CloseButtonProps, 'variant'>> = {
export const closeButtonVariantProps = {
filled: { bgColor: 'background.lightest', boxShadowSize: 'sm', color: 'primary.base' },
white: { color: 'text.lightest' },
} as const
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/CloseButton/CloseButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { MouseEventHandler, useState } from 'react'
import { type HTMLMotionProps } from 'framer-motion'
import { Relative } from '../Relative/Relative'
import { type BoxShadowSize, type IStyledSystemProps, type PaletteColor } from '../theme/theme'
import {
Expand All @@ -25,6 +26,9 @@ export type CloseButtonProps = IStyledSystemProps & {
variant?: CloseButtonVariant
}

/** @public */
export type MotionButtonProps = HTMLMotionProps<'button'> & CloseButtonProps

/**
* @public
*/
Expand All @@ -39,7 +43,7 @@ export const CloseButton = ({
title = 'close',
variant,
...props
}: CloseButtonProps) => {
}: MotionButtonProps) => {
const [hover, setHover] = useState(false)

return (
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Dialog/Dialog.styled.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Dialog from '@radix-ui/react-dialog'
import { VisuallyHidden } from '@radix-ui/react-visually-hidden'
import themeGet from '@styled-system/theme-get'
import { HTMLMotionProps, Transition, motion } from 'framer-motion'
import { Transition, motion } from 'framer-motion'
import React, { ReactElement } from 'react'
import styled from 'styled-components'
import { overflowX, overflowY, zIndex } from 'styled-system'
Expand Down Expand Up @@ -35,7 +35,7 @@ const scrimStyles = {

const enterTransition: Transition = { duration: 0.25, ease: 'easeOut' }
const exitTransition: Transition = { duration: 0.15, ease: 'easeIn' }
const animationStyles: Record<'default' | 'sheet' | 'overlay', HTMLMotionProps<'div'>> = {
const animationStyles = {
default: {
initial: { opacity: 0, scale: 0.9, translateY: 64 },
animate: { opacity: 1, scale: 1, translateY: 0, transition: enterTransition },
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Hug/Hug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type HugProps = CardProps & {
children?: React.ReactNode
iconDisplay?: string[]
icon?: React.ReactNode
text?: React.ReactNode | React.ReactNode[] | string
text?: React.ReactNode
color?: string
fontSize?: string | number
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Image/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { type ComponentPropsWithoutRef } from 'react'
import styled from 'styled-components'
import {
BorderRadiusProps,
Expand Down Expand Up @@ -42,7 +42,7 @@ export type ImageProps = BorderRadiusProps &
MinWidthProps &
SpaceProps &
WidthProps &
Partial<Omit<HTMLImageElement, 'width' | 'height'>> & {
Omit<ComponentPropsWithoutRef<'img'>, 'width' | 'height'> & {
borderRadiusSize?: string
rounded?: string
boxShadowSize?: string
Expand Down
Loading

0 comments on commit e760968

Please sign in to comment.