Skip to content

Commit

Permalink
fix: paragraph appearing as spans + className + typing issues (#24)
Browse files Browse the repository at this point in the history
* feat: add menu stories

* fix: typescript + paragraph element type
  • Loading branch information
PHILLIPS71 authored Apr 20, 2024
1 parent 277b0a8 commit 95f42ae
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 9 deletions.
17 changes: 14 additions & 3 deletions packages/react/src/components/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ type ComponentType = <T extends React.ElementType = typeof __ELEMENT_TYPE__>(

const Component: ComponentType = React.forwardRef(
<T extends React.ElementType = typeof __ELEMENT_TYPE__>(props: ComponentProps<T>, ref: Polymophic.Ref<T>) => {
const { as, children, isLoading = false, isDisabled = false, color, shape, size, variant, ...rest } = props
const {
as,
children,
className,
isLoading = false,
isDisabled = false,
color,
shape,
size,
variant,
...rest
} = props

const Element = as ?? Button

Expand All @@ -29,11 +40,11 @@ const Component: ComponentType = React.forwardRef(
const component = React.useMemo<ButtonProps>(
() => ({
'data-loading': isLoading,
className: slots.button(),
className: slots.button({ className: className?.toString() }),
isDisabled: isLoading || isDisabled,
...rest,
}),
[isDisabled, isLoading, rest, slots]
[className, isDisabled, isLoading, rest, slots]
)

return (
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/components/divider/Divider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type * as Polymophic from '@/utilities/polymorphic'
import type { DividerVariantProps } from '@giantnodes/theme'

import { divider } from '@giantnodes/theme'
import React from 'react'

const __ELEMENT_TYPE__ = 'hr'

type ComponentOwnProps = {
type ComponentOwnProps = DividerVariantProps & {
icon: React.ReactNode
}

Expand Down
47 changes: 47 additions & 0 deletions packages/react/src/components/menu/Menu.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { MenuProps } from '@/components/menu'
import type { Meta, StoryFn } from '@storybook/react'

import { menu } from '@giantnodes/theme'

import { Button } from '@/components/button'
import { Menu } from '@/components/menu'

const Component: Meta<typeof Menu> = {
title: 'Components/Menu',
component: Menu,
argTypes: {
size: {
control: { type: 'select' },
},
status: {
control: { type: 'select' },
},
variant: {
control: { type: 'select' },
},
},
}

const defaultProps = {
...menu.defaultVariants,
}

export const Default: StoryFn = (args: MenuProps) => (
<Menu {...args}>
<Button>Open</Button>

<Menu.Popover placement="bottom right">
<Menu.List>
<Menu.Item>First</Menu.Item>
<Menu.Item>Second</Menu.Item>
<Menu.Item>Third</Menu.Item>
</Menu.List>
</Menu.Popover>
</Menu>
)

Default.args = {
...defaultProps,
}

export default Component
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import type * as Polymophic from '@/utilities/polymorphic'
import type { TypographyVariantProps } from '@giantnodes/theme'
import type { TextProps } from 'react-aria-components'

import { typography } from '@giantnodes/theme'
import React from 'react'
import { Text } from 'react-aria-components'

const __ELEMENT_TYPE__ = 'p'

type ComponentOwnProps = TextProps & TypographyVariantProps
type ComponentOwnProps = TypographyVariantProps

type ComponentProps<T extends React.ElementType> = Polymophic.ComponentPropsWithRef<T, ComponentOwnProps>

Expand All @@ -20,11 +18,11 @@ const Component: ComponentType = React.forwardRef(
<T extends React.ElementType = typeof __ELEMENT_TYPE__>(props: ComponentProps<T>, ref: Polymophic.Ref<T>) => {
const { as, children, className, variant, ...rest } = props

const Element = as ?? Text
const Element = as ?? __ELEMENT_TYPE__

const slots = React.useMemo(() => typography({ variant }), [variant])

const component = React.useMemo<TextProps>(
const component = React.useMemo<React.ComponentPropsWithoutRef<typeof __ELEMENT_TYPE__>>(
() => ({
className: slots.paragraph({ className }),
...rest,
Expand Down

0 comments on commit 95f42ae

Please sign in to comment.