-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
73e51ca
commit 005e703
Showing
44 changed files
with
3,118 additions
and
246 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
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
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
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
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,93 @@ | ||
import React from 'react' | ||
import { cx } from '@sakura-ui/helper' | ||
import { Card, CardHeader } from './Card' | ||
import { Icon } from './Icon' | ||
|
||
interface LinkContextType { | ||
href: string | ||
} | ||
|
||
const LinkContext = React.createContext<LinkContextType>({ href: '' }) | ||
|
||
export interface LinkCardProps extends React.ComponentProps<'article'> { | ||
href: string | ||
} | ||
|
||
export const LinkCard = ({ | ||
href, | ||
className, | ||
children, | ||
...rest | ||
}: LinkCardProps) => { | ||
const styleLink = ` | ||
grid | ||
outline-offset-4 | ||
rounded-2xl | ||
sm:rounded-3xl | ||
focus:outline-2 | ||
focus:outline-wood-600 | ||
w-full h-full | ||
` | ||
|
||
const styleHover = ` | ||
hover:text-sea-1000 | ||
hover:border-sea-1000 | ||
` | ||
|
||
const isExternal = href?.startsWith('https://') | ||
|
||
return ( | ||
<LinkContext.Provider value={{ href: href }}> | ||
<a | ||
className={cx(styleLink)} | ||
href={href} | ||
target={isExternal ? '_blank' : ''} | ||
> | ||
<Card className={cx(styleHover, className)} {...rest}> | ||
{children} | ||
</Card> | ||
</a> | ||
</LinkContext.Provider> | ||
) | ||
} | ||
|
||
export interface LinkCardHeaderProps extends React.ComponentProps<'div'> {} | ||
|
||
export const LinkCardHeader = ({ | ||
className, | ||
children | ||
}: LinkCardHeaderProps) => { | ||
const { href } = React.useContext(LinkContext) | ||
|
||
const styleHeading = ` | ||
flex | ||
justify-between | ||
items-center | ||
` | ||
|
||
const isExternal = href.startsWith('https://') | ||
|
||
return ( | ||
<CardHeader className={cx(className, styleHeading)}> | ||
{href === '' ? ( | ||
children | ||
) : ( | ||
<> | ||
<span> | ||
{children} | ||
{isExternal ? ( | ||
<Icon className="text-base ml-1 font-light" icon="open_in_new" /> | ||
) : ( | ||
'' | ||
)} | ||
</span> | ||
{isExternal ? ( | ||
'' | ||
) : ( | ||
<Icon className="text-base-sm !font-medium" icon="arrow_forward" /> | ||
)} | ||
</> | ||
)} | ||
</CardHeader> | ||
) | ||
} |
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
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
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,40 @@ | ||
{ | ||
"name": "@sakura-ui/helper", | ||
"version": "0.0.2", | ||
"license": "MIT", | ||
"main": "dist/index.cjs.js", | ||
"types": "dist/types/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/types/index.d.ts", | ||
"require": "./dist/index.cjs.js", | ||
"import": "./dist/index.es.js" | ||
} | ||
}, | ||
"sideEffects": false, | ||
"files": [ | ||
"dist" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"lint": "run-s lint:*", | ||
"lint:lint": "biome lint ./", | ||
"lint:prettier": "prettier --write --ignore-path .gitignore './src/*.ts'", | ||
"prebuild": "rimraf dist", | ||
"build": "run-p build:*", | ||
"build:scripts": "vite build", | ||
"build:types": "tsc && tsc-alias", | ||
"test": "vitest" | ||
}, | ||
"devDependencies": { | ||
"@testing-library/jest-dom": "^6.4.5", | ||
"@testing-library/react": "^16.0.0", | ||
"@types/react": "^18.3.3", | ||
"@types/react-dom": "^18.3.0", | ||
"happy-dom": "^14.12.0", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1" | ||
} | ||
} |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { cx } from './cx' | ||
export { forwardRef } from './forward-ref' | ||
export type { ComponentWithAs } from './types/component' | ||
export { treefy } from './treefy' |
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,22 @@ | ||
type TreeNode<I> = Omit<I, 'children'> & { children?: TreeNode<I>[] } | ||
type Input<I> = (I & { children: unknown })[] | ||
|
||
export const treefy = <I extends { depth: number }>(input: I[]) => { | ||
const tree: TreeNode<I>[] = [] | ||
const last: TreeNode<I>[] = [] | ||
let top = -1 | ||
let bottom = -1 | ||
for (const { children: _, ...item } of input as Input<I>) { | ||
if (top < item.depth && item.depth <= bottom + 1) { | ||
const idx = item.depth - top | ||
bottom = item.depth | ||
;(last[idx - 1].children ??= []).push(item) | ||
last[idx] = item | ||
continue | ||
} | ||
tree.push(item) | ||
last[0] = item | ||
top = bottom = item.depth | ||
} | ||
return tree | ||
} |
File renamed without changes.
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,13 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"declarationDir": "./dist/types", | ||
"outDir": "./dist", | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": ["src/*"] | ||
} | ||
}, | ||
"include": ["src"], | ||
"references": [{ "path": "./tsconfig.node.json" }] | ||
} |
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,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true | ||
}, | ||
"include": ["vite.config.ts"] | ||
} |
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,26 @@ | ||
/// <reference types="vitest" /> | ||
import { resolve } from 'node:path' | ||
import { defineConfig } from 'vite' | ||
import react from '@vitejs/plugin-react-swc' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()], | ||
resolve: { | ||
alias: { | ||
'@': resolve(__dirname, 'src') | ||
} | ||
}, | ||
build: { | ||
lib: { | ||
entry: resolve(__dirname, 'src', 'index.ts'), | ||
formats: ['es', 'cjs'], | ||
fileName: (ext: string) => `index.${ext}.js` | ||
} | ||
}, | ||
test: { | ||
globals: true, | ||
environment: 'happy-dom', | ||
setupFiles: 'tests/vitest.setup.ts' | ||
} | ||
}) |
Oops, something went wrong.