Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: paragraph appearing as spans + className + typing issues #24

Merged
merged 2 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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