Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/twelve-dryers-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/react": patch
---

Support props and custom component in as
7 changes: 5 additions & 2 deletions packages/react/src/components/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { DevupComponentProps } from '../types/props'
import type {
DevupComponentBaseProps,
DevupComponentProps,
} from '../types/props'
import type { Merge } from '../types/utils'

export function Box<T extends React.ElementType = 'div'>(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
props: Merge<React.ComponentProps<T>, DevupComponentProps<T>>,
props: Merge<DevupComponentBaseProps<T>, DevupComponentProps<T>>,
): React.ReactElement {
throw new Error('Cannot run on the runtime')
}
7 changes: 5 additions & 2 deletions packages/react/src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { DevupComponentProps } from '../types/props'
import type {
DevupComponentBaseProps,
DevupComponentProps,
} from '../types/props'
import type { Merge } from '../types/utils'

export function Button<T extends React.ElementType = 'button'>(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
props: Merge<React.ComponentProps<T>, DevupComponentProps<T>>,
props: Merge<DevupComponentBaseProps<T>, DevupComponentProps<T>>,
): React.ReactElement {
throw new Error('Cannot run on the runtime')
}
7 changes: 5 additions & 2 deletions packages/react/src/components/Center.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { DevupComponentProps } from '../types/props'
import type {
DevupComponentBaseProps,
DevupComponentProps,
} from '../types/props'
import type { Merge } from '../types/utils'

export function Center<T extends React.ElementType = 'div'>(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
props: Merge<React.ComponentProps<T>, DevupComponentProps<T>>,
props: Merge<DevupComponentBaseProps<T>, DevupComponentProps<T>>,
): React.ReactElement {
throw new Error('Cannot run on the runtime')
}
7 changes: 5 additions & 2 deletions packages/react/src/components/Flex.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { DevupComponentProps } from '../types/props'
import type {
DevupComponentBaseProps,
DevupComponentProps,
} from '../types/props'
import type { Merge } from '../types/utils'

export function Flex<T extends React.ElementType = 'div'>(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
props: Merge<React.ComponentProps<T>, DevupComponentProps<T>>,
props: Merge<DevupComponentBaseProps<T>, DevupComponentProps<T>>,
): React.ReactElement {
throw new Error('Cannot run on the runtime')
}
7 changes: 5 additions & 2 deletions packages/react/src/components/Grid.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { DevupComponentProps } from '../types/props'
import type {
DevupComponentBaseProps,
DevupComponentProps,
} from '../types/props'
import type { Merge } from '../types/utils'

export function Grid<T extends React.ElementType = 'div'>(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
props: Merge<React.ComponentProps<T>, DevupComponentProps<T>>,
props: Merge<DevupComponentBaseProps<T>, DevupComponentProps<T>>,
): React.ReactElement {
throw new Error('Cannot run on the runtime')
}
7 changes: 5 additions & 2 deletions packages/react/src/components/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { DevupComponentProps } from '../types/props'
import type {
DevupComponentBaseProps,
DevupComponentProps,
} from '../types/props'
import type { Merge } from '../types/utils'

export function Image<T extends React.ElementType = 'img'>(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
props: Merge<React.ComponentProps<T>, DevupComponentProps<T>>,
props: Merge<DevupComponentBaseProps<T>, DevupComponentProps<T>>,
): React.ReactElement {
throw new Error('Cannot run on the runtime')
}
7 changes: 5 additions & 2 deletions packages/react/src/components/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { DevupComponentProps } from '../types/props'
import type {
DevupComponentBaseProps,
DevupComponentProps,
} from '../types/props'
import type { Merge } from '../types/utils'

export function Input<T extends React.ElementType = 'input'>(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
props: Merge<React.ComponentProps<T>, DevupComponentProps<T>>,
props: Merge<DevupComponentBaseProps<T>, DevupComponentProps<T>>,
): React.ReactElement {
throw new Error('Cannot run on the runtime')
}
7 changes: 5 additions & 2 deletions packages/react/src/components/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { DevupComponentProps } from '../types/props'
import type {
DevupComponentBaseProps,
DevupComponentProps,
} from '../types/props'
import type { Merge } from '../types/utils'

export function Text<T extends React.ElementType = 'span'>(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
props: Merge<React.ComponentProps<T>, DevupComponentProps<T>>,
props: Merge<DevupComponentBaseProps<T>, DevupComponentProps<T>>,
): React.ReactElement {
throw new Error('Cannot run on the runtime')
}
7 changes: 5 additions & 2 deletions packages/react/src/components/VStack.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { DevupComponentProps } from '../types/props'
import type {
DevupComponentBaseProps,
DevupComponentProps,
} from '../types/props'
import type { Merge } from '../types/utils'

export function VStack<T extends React.ElementType = 'div'>(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
props: Merge<React.ComponentProps<T>, DevupComponentProps<T>>,
props: Merge<DevupComponentBaseProps<T>, DevupComponentProps<T>>,
): React.ReactElement {
throw new Error('Cannot run on the runtime')
}
17 changes: 17 additions & 0 deletions packages/react/src/types/props/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,20 @@ export interface DevupComponentProps<T extends React.ElementType>
as?: T
styleVars?: Record<string, string | undefined>
}
export type DevupComponentBaseProps<T extends React.ElementType> =
DevupElementTypeProps<T> & DevupComponentAdditionalProps<T>

export type DevupElementTypeProps<T extends React.ElementType> =
T extends string ? React.ComponentProps<T> : object

export type DevupComponentAdditionalProps<
T extends React.ElementType,
P extends React.ComponentProps<T> = React.ComponentProps<T>,
> =
Partial<P> extends P
? {
props?: P
}
: {
props: P
}