@amboss/design-system 3.35.4 → 3.35.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,9 +2,13 @@ import { type AriaAttributes, type ReactElement } from "react";
2
2
  import { type InlineProps } from "../Inline/Inline";
3
3
  import { type ColorPickerOptionProps } from "./ColorPickerOption";
4
4
  import type { ColorIndicatorProps } from "../ColorIndicator/ColorIndicator";
5
+ export type ColorOption = {
6
+ color: ColorIndicatorProps["color"];
7
+ ariaLabel: string;
8
+ };
5
9
  export type ColorPickerProps = Pick<ColorPickerOptionProps, "size"> & {
6
10
  alignItems?: InlineProps["alignItems"];
7
- colors?: Array<ColorIndicatorProps["color"]>;
11
+ colors: Array<ColorOption>;
8
12
  disabled?: boolean;
9
13
  onColorSelected: (color: ColorPickerOptionProps["color"]) => void;
10
14
  selectedColor?: ColorPickerOptionProps["color"];
@@ -1 +1 @@
1
- import React from"react";import{Inline}from"../Inline/Inline";import{Button}from"../Button/Button";import{ColorPickerOption}from"./ColorPickerOption";export const ColorPicker=({alignItems="left",colors=["gray","blue","green","yellow","red","purple"],onColorSelected,disabled,selectedColor,size=["m","s"],ariaAttributes:deprecatedAriaAttributes,...ariaAttributes})=>React.createElement(Inline,{space:"s"===size?"zero":"xxxs",alignItems:alignItems},colors.map(color=>React.createElement(Button,{key:color,variant:"tertiary",size:"s",onClick:()=>onColorSelected(color),disabled:disabled,"data-color":color,ariaAttributes:{"aria-label":`button-${color}`,...deprecatedAriaAttributes},...ariaAttributes},React.createElement(ColorPickerOption,{"data-e2e-test-id":"color-indicator",color:color,isSelected:color===selectedColor,size:size}))));
1
+ import React,{useRef}from"react";import{Inline}from"../Inline/Inline";import{Button}from"../Button/Button";import{ColorPickerOption}from"./ColorPickerOption";import{useKeyboard}from"../../shared/useKeyboard";export const ColorPicker=({alignItems="left",colors,onColorSelected,disabled,selectedColor,size=["m","s"],ariaAttributes:deprecatedAriaAttributes,...ariaAttributes})=>{let selectedIndex=selectedColor?colors.findIndex(c=>c.color===selectedColor):-1,tabbableIndex=selectedIndex>=0?selectedIndex:0,groupRef=useRef(null),focusedIndex=useRef(tabbableIndex),focusByDelta=delta=>{let buttons=groupRef.current?.querySelectorAll("[data-color]");if(!buttons)return;let next=(focusedIndex.current+delta+buttons.length)%buttons.length;focusedIndex.current=next,buttons[next]?.focus(),onColorSelected(colors[next].color)};return useKeyboard({"ArrowRight ArrowDown":()=>focusByDelta(1),"ArrowLeft ArrowUp":()=>focusByDelta(-1),"Enter Space":()=>onColorSelected(colors[focusedIndex.current].color)},groupRef,!disabled),React.createElement("div",{ref:groupRef,role:"radiogroup",...deprecatedAriaAttributes,...ariaAttributes},React.createElement(Inline,{space:"s"===size?"zero":"xxxs",alignItems:alignItems},colors.map((colorOption,index)=>React.createElement(Button,{key:colorOption.color,variant:"tertiary",size:"s",onClick:()=>onColorSelected(colorOption.color),onFocus:()=>{focusedIndex.current=index},disabled:disabled,"data-color":colorOption.color,role:"radio","aria-checked":colorOption.color===selectedColor,tabIndex:index===tabbableIndex?0:-1,"aria-label":colorOption.ariaLabel},React.createElement(ColorPickerOption,{"data-e2e-test-id":"color-indicator",color:colorOption.color,isSelected:colorOption.color===selectedColor,size:size})))))};