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

render prop, exclusive union #11

Merged
merged 3 commits into from
Oct 27, 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
63 changes: 31 additions & 32 deletions src/packages/utils/shared/.gitignore
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz
node_modules

# testing
/coverage
# build
dist
dist-ssr
build
out
*.tsbuildinfo

# next.js
/.next/
/out/
# testing & coverage
coverage
coverage-ts

# production
/build
/dist
# env
.env

# misc
.DS_Store
# Editor directories and files
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.local
*.pem
.idea
.todo
.DS_Store

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env
.env*.local

# turbo
# vendors
.turbo

# vercel
.vercel

# typescript
*.tsbuildinfo

# coverage-ts
coverage-ts
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
15 changes: 14 additions & 1 deletion src/packages/utils/shared/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,17 @@

### Patch changes

- Add and export getOptionalObject and mergeProps utility functions
- Add getOptionalObject and mergeProps utility functions

## 0.2.6

### Patch changes

- Add color & simplify types

## 0.2.7

### Patch changes

- Add render prop utility, used to return a node or call a function with it's arguments which returns a node
- Add exclusive union type
100 changes: 49 additions & 51 deletions src/packages/utils/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
{
"author": {
"email": "[email protected]",
"name": "Lovro Žagar"
},
"dependencies": {
"@radix-ui/react-polymorphic": "0.0.14",
"class-variance-authority": "^0.7.0",
"tailwind-merge": ">=2.5.4"
},
"devDependencies": {
"bunchee": "^5.5.1",
"react": "19.0.0-rc-a960b92c-20240819",
"react-dom": "19.0.0-rc-a960b92c-20240819",
"types-react": "^19.0.0-rc.1",
"types-react-dom": "^19.0.0-rc.1",
"typescript": "^5.5.4"
},
"exports": {
".": {
"import": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
}
}
},
"files": [
"dist"
],
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/index.js",
"name": "@renderui/utils",
"peerDependencies": {
"react": ">=18",
"react-dom": ">=18"
},
"private": false,
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/lovrozagar/renderui.git"
},
"scripts": {
"build": "bunchee -m"
},
"type": "module",
"types": "./dist/index.d.ts",
"version": "0.2.6"
}
"author": {
"email": "[email protected]",
"name": "Lovro Žagar"
},
"dependencies": {
"@radix-ui/react-polymorphic": "0.0.14",
"class-variance-authority": "^0.7.0",
"tailwind-merge": ">=2.5.4"
},
"devDependencies": {
"bunchee": "^5.5.1",
"react": "19.0.0-rc-a960b92c-20240819",
"react-dom": "19.0.0-rc-a960b92c-20240819",
"types-react": "^19.0.0-rc.1",
"types-react-dom": "^19.0.0-rc.1",
"typescript": "^5.5.4"
},
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"files": ["dist"],
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/index.js",
"name": "@renderui/utils",
"peerDependencies": {
"react": ">=18",
"react-dom": ">=18"
},
"private": false,
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/lovrozagar/renderui.git"
},
"scripts": {
"build": "bunchee -m"
},
"type": "module",
"types": "./dist/index.d.ts",
"version": "0.2.7"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never }

type ExclusiveUnion<T, U> = T | U extends Record<string, unknown>
? (Without<T, U> & U) | (Without<U, T> & T)
: T | U

export type { ExclusiveUnion }
3 changes: 2 additions & 1 deletion src/packages/utils/shared/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { chain } from "./chain/chain"
export { cn, type CnOptions } from "./cn/cn"
export type { Color } from "./color/color"
export { composeEventHandlers } from "./compose-event-handlers/compose-event-handlers"
export { cva, type VariantProps } from "./cva/cva"
export { cx, type CxOptions } from "./cx/cx"
Expand All @@ -11,5 +12,5 @@ export {
export { mergeProps } from "./merge-props/merge-props"
export { noop } from "./noop/noop"
export { polymorphic, type PolymorphicProps } from "./polymorphic/polymorphic"
export type { Color } from "./color/color"
export { renderProp } from "./render-prop/render-prop"
export type { Simplify } from "./simplify/simplify"
12 changes: 12 additions & 0 deletions src/packages/utils/shared/src/render-prop/render-prop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function renderProp<T, A extends unknown[]>(
nodeOrFunction: T | ((...functionArgs: A) => T),
...args: A
) {
if (typeof nodeOrFunction === "function") {
return (nodeOrFunction as (...functionArgs: A) => T)(...args)
}

return nodeOrFunction as T
}

export { renderProp }
4 changes: 2 additions & 2 deletions src/packages/utils/shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "../../../../tsconfig.json",
"include": ["src", "index.ts"]
"extends": "../../../../tsconfig.json",
"include": ["src"]
}
Loading