Skip to content

Commit

Permalink
Merge pull request #3677 from Lenghak/main
Browse files Browse the repository at this point in the history
style(emoji & color picker): fix styling & dependencies with color pi…
  • Loading branch information
zbeyens authored Oct 31, 2024
2 parents 3f9f97c + 3df78e6 commit c217b6b
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 106 deletions.
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Use the [CLI](https://platejs.org/docs/components/cli) to install the latest ver

## October 2024 #15

### October 27 #15.6

- Fixed and modified some styles in emoji and color picker

### October 26 #15.5

- Rename `indent-todo-marker-component` to `indent-todo-marker`.
Expand Down
8 changes: 4 additions & 4 deletions apps/www/public/r/styles/default/color-dropdown-menu.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apps/www/public/r/styles/default/emoji-dropdown-menu.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions apps/www/src/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
CornerUpLeft,
DownloadCloud,
DownloadIcon,
EraserIcon,
ExternalLink,
Eye,
File,
Expand Down Expand Up @@ -418,6 +419,7 @@ export const Icons = {
code: Code2,
codeblock: FileCode,
color: Baseline,
colorClear: EraserIcon,
column: RectangleVertical,
combine: Combine,
comment: MessageSquare,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import type { DropdownMenuItemProps } from '@radix-ui/react-dropdown-menu';
import { cn } from '@udecode/cn';
import { Check } from 'lucide-react';

import type { TColor } from './color-dropdown-menu';

import { buttonVariants } from './button';
import { DropdownMenuItem } from './dropdown-menu';
import {
Expand All @@ -18,6 +16,12 @@ import {
TooltipTrigger,
} from './tooltip';

export type TColor = {
isBrightColor: boolean;
name: string;
value: string;
};

type ColorDropdownMenuItemProps = {
isBrightColor: boolean;
isSelected: boolean;
Expand All @@ -42,8 +46,8 @@ export function ColorDropdownMenuItem({
isMenu: true,
variant: 'outline',
}),
'size-6 border border-solid border-muted p-0',
!isBrightColor && 'border-transparent text-white',
'flex size-6 items-center justify-center rounded-full border border-solid border-muted p-0 transition-all hover:scale-125',
!isBrightColor && 'border-transparent text-white hover:!text-white',
className
)}
style={{ backgroundColor: value }}
Expand All @@ -53,14 +57,14 @@ export function ColorDropdownMenuItem({
}}
{...props}
>
{isSelected ? <Check /> : null}
{isSelected ? <Check className="size-3" /> : null}
</DropdownMenuItem>
);

return name ? (
<Tooltip>
<TooltipTrigger>{content}</TooltipTrigger>
<TooltipContent>{name}</TooltipContent>
<TooltipContent className="mb-1 capitalize">{name}</TooltipContent>
</Tooltip>
) : (
content
Expand All @@ -82,7 +86,10 @@ export function ColorDropdownMenuItems({
}: ColorDropdownMenuItemsProps) {
return (
<div
className={cn('grid grid-cols-[repeat(10,1fr)] gap-1', className)}
className={cn(
'grid grid-cols-[repeat(10,1fr)] place-items-center gap-1',
className
)}
{...props}
>
<TooltipProvider>
Expand All @@ -96,6 +103,7 @@ export function ColorDropdownMenuItems({
updateColor={updateColor}
/>
))}
{props.children}
</TooltipProvider>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use client';

import React from 'react';

import type { DropdownMenuProps } from '@radix-ui/react-dropdown-menu';

import {
Expand All @@ -18,12 +16,6 @@ import {
} from './dropdown-menu';
import { ToolbarButton } from './toolbar';

export type TColor = {
isBrightColor: boolean;
name: string;
value: string;
};

type ColorDropdownMenuProps = {
nodeType: string;
tooltip?: string;
Expand Down
86 changes: 52 additions & 34 deletions apps/www/src/registry/default/plate-ui/color-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import React from 'react';

import { cn, withRef } from '@udecode/cn';

import type { TColor } from './color-dropdown-menu';
import { Icons } from '@/components/icons';

import { buttonVariants } from './button';
import { ColorDropdownMenuItems } from './color-dropdown-menu-items';
import { ColorsCustom } from './colors-custom';
import { DropdownMenuItem } from './dropdown-menu';
import { Separator } from './separator';
import {
type TColor,
ColorDropdownMenuItems,
} from './color-dropdown-menu-items';
import { ColorCustom } from './colors-custom';
import {
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
} from './dropdown-menu';

export const ColorPickerContent = withRef<
'div',
Expand All @@ -37,36 +44,47 @@ export const ColorPickerContent = withRef<
ref
) => {
return (
<div
ref={ref}
className={cn('flex flex-col gap-4 p-4', className)}
{...props}
>
<ColorsCustom
color={color}
colors={colors}
customColors={customColors}
updateColor={updateColor}
updateCustomColor={updateCustomColor}
/>

<Separator />

<ColorDropdownMenuItems
color={color}
colors={colors}
updateColor={updateColor}
/>
<div ref={ref} className={cn('flex flex-col', className)} {...props}>
<DropdownMenuLabel>Color Picker</DropdownMenuLabel>
<DropdownMenuGroup>
<ColorCustom
color={color}
className="p-2"
colors={colors}
customColors={customColors}
updateColor={updateColor}
updateCustomColor={updateCustomColor}
/>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<ColorDropdownMenuItems
color={color}
className="p-2"
colors={colors}
updateColor={updateColor}
/>
</DropdownMenuGroup>
{color && (
<DropdownMenuItem
className={buttonVariants({
isMenu: true,
variant: 'outline',
})}
onClick={clearColor}
>
Clear
</DropdownMenuItem>
<React.Fragment>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem
className={cn(
buttonVariants({
isMenu: false,
size: 'sm',
variant: 'ghost',
}),
'w-full justify-start'
)}
onClick={clearColor}
>
<Icons.colorClear className="mr-2" />
<span>Clear</span>
</DropdownMenuItem>
</DropdownMenuGroup>
</React.Fragment>
)}
</div>
);
Expand Down
55 changes: 34 additions & 21 deletions apps/www/src/registry/default/plate-ui/colors-custom.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
'use client';

import React from 'react';
import React, { type ComponentPropsWithoutRef } from 'react';

import { cn } from '@udecode/cn';
import {
useColorsCustom,
useColorsCustomState,
} from '@udecode/plate-font/react';

import type { TColor } from './color-dropdown-menu';
import { Icons } from '@/components/icons';

import { buttonVariants } from './button';
import { ColorDropdownMenuItems } from './color-dropdown-menu-items';
import {
type TColor,
ColorDropdownMenuItems,
} from './color-dropdown-menu-items';
import { ColorInput } from './color-input';

// import { ColorInput } from './color-input';
import { DropdownMenuItem } from './dropdown-menu';

type ColorsCustomProps = {
type ColorCustomProps = {
colors: TColor[];
customColors: TColor[];
updateColor: (color: string) => void;
updateCustomColor: (color: string) => void;
color?: string;
};
} & ComponentPropsWithoutRef<'div'>;

export function ColorsCustom({
export function ColorCustom({
className,
color,
colors,
customColors,
updateColor,
updateCustomColor,
}: ColorsCustomProps) {
...props
}: ColorCustomProps) {
const state = useColorsCustomState({
color,
colors,
Expand All @@ -38,24 +46,29 @@ export function ColorsCustom({
const { inputProps, menuItemProps } = useColorsCustom(state);

return (
<div className="flex flex-col gap-4">
<ColorInput {...inputProps}>
<DropdownMenuItem
className={buttonVariants({
isMenu: true,
variant: 'outline',
})}
{...menuItemProps}
>
CUSTOM
</DropdownMenuItem>
</ColorInput>

<div className={cn('relative flex flex-col gap-4', className)} {...props}>
<ColorDropdownMenuItems
color={color}
colors={state.computedColors}
updateColor={updateColor}
/>
>
<ColorInput {...inputProps}>
<DropdownMenuItem
className={cn(
buttonVariants({
isMenu: true,
size: 'icon',
variant: 'outline',
}),
'absolute bottom-2 right-2 top-1.5 flex size-7 items-center justify-center rounded-full'
)}
{...menuItemProps}
>
<span className="sr-only">Custom</span>
<Icons.add />
</DropdownMenuItem>
</ColorInput>
</ColorDropdownMenuItems>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Button = memo(
className="absolute inset-0 rounded-full opacity-0 group-hover:opacity-100"
aria-hidden="true"
/>
<span style={{ position: 'relative' }} data-emoji-set="native">
<span className="relative" data-emoji-set="native">
{emoji.skins[0].native}
</span>
</button>
Expand Down
Loading

0 comments on commit c217b6b

Please sign in to comment.