-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from Cloud-Code-AI/201-custom-component-block
201 custom component block
- Loading branch information
Showing
17 changed files
with
699 additions
and
46 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
packages/akiradocs/src/components/blocks/ButtonBlock.tsx
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,103 @@ | ||
import { cn } from "@/lib/utils" | ||
import { Button, buttonVariants } from "@/components/ui/button" | ||
import { useState } from "react" | ||
|
||
interface ButtonBlockProps { | ||
content: string | ||
metadata?: { | ||
buttonUrl?: string | ||
buttonStyle?: { | ||
variant?: 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link' | ||
size?: 'default' | 'sm' | 'lg' | ||
radius?: 'none' | 'sm' | 'md' | 'lg' | 'full' | ||
} | ||
} | ||
isEditing?: boolean | ||
onUpdate?: (content: string) => void | ||
align?: 'left' | 'center' | 'right' | ||
} | ||
|
||
export function ButtonBlock({ | ||
content, | ||
metadata, | ||
isEditing, | ||
onUpdate, | ||
align = 'left' | ||
}: ButtonBlockProps) { | ||
const [isFocused, setIsFocused] = useState(false); | ||
const buttonStyle = metadata?.buttonStyle || {} | ||
const url = metadata?.buttonUrl || '#' | ||
|
||
const buttonClasses = cn( | ||
"relative", | ||
{ | ||
'rounded-none': buttonStyle.radius === 'none', | ||
'rounded-sm': buttonStyle.radius === 'sm', | ||
'rounded-md': buttonStyle.radius === 'md', | ||
'rounded-lg': buttonStyle.radius === 'lg', | ||
'rounded-full': buttonStyle.radius === 'full', | ||
'w-full': buttonStyle.size === 'lg', | ||
'w-24': buttonStyle.size === 'sm', | ||
'w-auto': buttonStyle.size === 'default' | ||
} | ||
) | ||
|
||
const wrapperClasses = cn( | ||
'w-full', | ||
{ | ||
'text-left': align === 'left', | ||
'text-center': align === 'center', | ||
'text-right': align === 'right' | ||
} | ||
) | ||
|
||
if (isEditing) { | ||
return ( | ||
<div className={wrapperClasses}> | ||
<div className="relative inline-block"> | ||
<Button | ||
variant={buttonStyle.variant || 'default'} | ||
size={buttonStyle.size || 'default'} | ||
className={cn(buttonClasses, isFocused && "invisible")} | ||
type="button" | ||
> | ||
{content || 'Button text...'} | ||
</Button> | ||
<input | ||
value={content} | ||
onChange={(e) => onUpdate?.(e.target.value)} | ||
onFocus={() => setIsFocused(true)} | ||
onBlur={() => setIsFocused(false)} | ||
className={cn( | ||
buttonVariants({ | ||
variant: buttonStyle.variant || 'default', | ||
size: buttonStyle.size || 'default' | ||
}), | ||
buttonClasses, | ||
"absolute inset-0 border-0 outline-none", | ||
!isFocused && "opacity-0" | ||
)} | ||
placeholder="Button text..." | ||
/> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
<div className={wrapperClasses}> | ||
<div className="relative inline-block"> | ||
<Button | ||
variant={buttonStyle.variant || 'default'} | ||
size={buttonStyle.size || 'default'} | ||
className={buttonClasses} | ||
asChild | ||
> | ||
<a href={url} target="_blank" rel="noopener noreferrer"> | ||
{content} | ||
</a> | ||
</Button> | ||
</div> | ||
</div> | ||
) | ||
} |
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,59 @@ | ||
import { cn } from '@/lib/utils' | ||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' | ||
import { useState } from 'react' | ||
|
||
interface SpacerBlockProps { | ||
size?: 'small' | 'medium' | 'large' | 'xlarge' | ||
isEditing?: boolean | ||
onUpdate?: (size: string) => void | ||
} | ||
|
||
const spacingSizes = { | ||
small: 'h-4', | ||
medium: 'h-8', | ||
large: 'h-16', | ||
xlarge: 'h-24' | ||
} | ||
|
||
export function SpacerBlock({ size = 'medium', isEditing, onUpdate }: SpacerBlockProps) { | ||
const [isFocused, setIsFocused] = useState(false) | ||
|
||
if (!isEditing) { | ||
return <div className={cn('w-full', spacingSizes[size])} /> | ||
} | ||
|
||
return ( | ||
<div | ||
className="flex items-center gap-2 py-2" | ||
tabIndex={0} | ||
onFocus={() => setIsFocused(true)} | ||
onBlur={(e) => { | ||
if (!e.currentTarget.contains(e.relatedTarget)) { | ||
setIsFocused(false) | ||
} | ||
}} | ||
> | ||
<div className={cn( | ||
'flex-grow border-2 border-dashed rounded transition-colors duration-200', | ||
spacingSizes[size], | ||
isFocused ? 'border-muted-foreground/20' : 'border-transparent' | ||
)} /> | ||
{isFocused && ( | ||
<Select | ||
value={size} | ||
onValueChange={(value) => onUpdate?.(value)} | ||
> | ||
<SelectTrigger className="w-[120px]"> | ||
<SelectValue placeholder="Select size" /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
<SelectItem value="small">Small</SelectItem> | ||
<SelectItem value="medium">Medium</SelectItem> | ||
<SelectItem value="large">Large</SelectItem> | ||
<SelectItem value="xlarge">Extra Large</SelectItem> | ||
</SelectContent> | ||
</Select> | ||
)} | ||
</div> | ||
) | ||
} |
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
Oops, something went wrong.