Skip to content

Commit

Permalink
feat: Working
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Jul 23, 2024
1 parent 9a4266e commit 34d69a5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/components/LayerController/AddChannelButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function AddChannelButton() {
</SelectTrigger>
<SelectContent className="focus:ring-0 border-none">
{source.names.map((name, i) => (
<SelectItem value={String(i)} key={name}>
<SelectItem className="text-xs" value={String(i)} key={name}>
{name}
</SelectItem>
))}
Expand Down
38 changes: 23 additions & 15 deletions src/components/LayerController/ChannelOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Separator } from "@/components/ui/separator";
import { useLayer, useSourceValue } from "@/hooks";
import { clamp } from "@/utils";
import ColorPalette from "./ColorPalette";
import { COLORS, clamp, hexToRGB } from "@/utils";

const RGB_COLORS: [string, string][] = Object.entries(COLORS);

function ChannelOptions(props: { channelIndex: number }) {
const { channelIndex: i } = props;
Expand Down Expand Up @@ -96,7 +97,7 @@ function ChannelOptions(props: { channelIndex: number }) {
</SelectTrigger>
<SelectContent className="focus:ring-0 border-none">
{names.map((name, i) => (
<SelectItem value={String(i)} key={name}>
<SelectItem className="text-xs" value={String(i)} key={name}>
{name}
</SelectItem>
))}
Expand All @@ -120,18 +121,25 @@ function ChannelOptions(props: { channelIndex: number }) {
<Separator />
<span className="text-xs">color:</span>
<Separator />
<div style={{ display: "flex", justifyContent: "center" }}>
<ColorPalette
handleChange={(rgb) => {
setLayer(({ layerProps, ...rest }) => ({
...rest,
layerProps: {
...layerProps,
colors: layerProps.colors.with(i, rgb),
},
}));
}}
/>
<div className="flex items-center justify-between" aria-label="color-swatch">
{RGB_COLORS.map(([name, rgb]) => (
<button
type="button"
aria-label={name}
style={{ backgroundColor: rgb }}
className="w-3.5 h-3.5 rounded-full cursor-pointer"
key={name}
onClick={() => {
setLayer(({ layerProps, ...rest }) => ({
...rest,
layerProps: {
...layerProps,
colors: layerProps.colors.with(i, hexToRGB(rgb)),
},
}));
}}
/>
))}
</div>
</PopoverContent>
</Popover>
Expand Down
40 changes: 0 additions & 40 deletions src/components/LayerController/ColorPalette.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion src/components/LayerController/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/
import { Separator } from "@/components/ui/separator";
import { Slider } from "@/components/ui/slider";
import { useLayer, useSourceValue } from "@/hooks";
import { range } from "@/utils";

/** Get the { name, idx, size } for each axis that is not the channel_axis and has size > 1 */
function axisSliders(info: {
Expand Down Expand Up @@ -99,7 +100,7 @@ function LayerController() {
</div>
<Separator />
<div>
{Array.from({ length: nChannels }).map((_, i) => (
{range(nChannels).map((i) => (
<ChannelController channelIndex={i} key={`${name}-${i}`} />
))}
</div>
Expand Down

0 comments on commit 34d69a5

Please sign in to comment.