-
-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zbeyens
committed
Dec 23, 2023
1 parent
77bff62
commit 54d4df7
Showing
7 changed files
with
95 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
--- | ||
|
||
- add support for custom tailwind prefix | ||
- add `extend` and `create` to `lib/utils.tsx` | ||
- minify build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { | ||
createElement, | ||
ElementRef, | ||
forwardRef, | ||
ForwardRefExoticComponent, | ||
} from 'react'; | ||
import { clsx } from 'clsx'; | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
import type { ClassValue } from 'clsx'; | ||
|
||
export function cn(...inputs: ClassValue[]) { | ||
return twMerge(clsx(inputs)); | ||
} | ||
|
||
export function extend<T extends { className?: string }>( | ||
Component: ForwardRefExoticComponent<T>, | ||
defaultProps: T | ||
) { | ||
return forwardRef<ElementRef<typeof Component>, T>( | ||
function ExtendComponent(props, ref) { | ||
return ( | ||
<Component | ||
ref={ref} | ||
{...defaultProps} | ||
{...props} | ||
className={cn(defaultProps.className, props.className)} | ||
/> | ||
); | ||
} | ||
); | ||
} | ||
|
||
export function create<T extends keyof HTMLElementTagNameMap>(tag: T) { | ||
return forwardRef<HTMLElementTagNameMap[T], JSX.IntrinsicElements[T]>( | ||
function CreateComponent(props, ref) { | ||
return createElement(tag, { ...props, ref }); | ||
} | ||
); | ||
} | ||
|
||
export function formatDate(input: string | number): string { | ||
const date = new Date(input); | ||
return date.toLocaleDateString('en-US', { | ||
month: 'long', | ||
day: 'numeric', | ||
year: 'numeric', | ||
}); | ||
} | ||
|
||
export function absoluteUrl(path: string) { | ||
return `${process.env.NEXT_PUBLIC_APP_URL}${path}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters