@@ -9,16 +9,18 @@ export class UserPaletteControl {
99
1010 bind ( ) {
1111 this . renderSortOptions ( ) ;
12- this . refs . userPaletteSortSelect . addEventListener ( "change" , ( ) => {
13- this . app . setUserSortMode ( this . refs . userPaletteSortSelect . value ) ;
12+ this . renderSizeOptions ( ) ;
13+ this . refs . userSwatchSizeSelect . addEventListener ( "change" , ( ) => {
14+ this . app . setSwatchSize ( this . refs . userSwatchSizeSelect . value ) ;
1415 } ) ;
1516 }
1617
1718 render ( ) {
1819 const swatches = this . app . getUserSwatches ( ) ;
1920 this . refs . userPaletteCount . textContent = `${ swatches . length } user swatches` ;
20- this . refs . userPaletteSortSelect . value = this . app . getUserSortMode ( ) ;
21+ this . refs . userSwatchSizeSelect . value = this . app . getSwatchSize ( ) ;
2122 this . refs . userSwatchList . dataset . swatchSize = this . app . getSwatchSize ( ) ;
23+ this . renderActiveSortButton ( ) ;
2224 this . refs . userSwatchList . replaceChildren ( ) ;
2325
2426 if ( swatches . length === 0 ) {
@@ -40,12 +42,38 @@ export class UserPaletteControl {
4042 }
4143
4244 renderSortOptions ( ) {
43- this . refs . userPaletteSortSelect . replaceChildren ( ) ;
45+ this . refs . userPaletteSortControls . replaceChildren ( ) ;
4446 this . app . getSortModes ( ) . forEach ( ( mode ) => {
47+ const button = this . document . createElement ( "button" ) ;
48+ button . type = "button" ;
49+ button . className = "palette-manager-v2__sort-button" ;
50+ button . dataset . sortMode = mode . value ;
51+ button . setAttribute ( "role" , "radio" ) ;
52+ button . textContent = mode . label ;
53+ button . addEventListener ( "click" , ( ) => {
54+ this . app . setUserSortMode ( mode . value ) ;
55+ } ) ;
56+ this . refs . userPaletteSortControls . appendChild ( button ) ;
57+ } ) ;
58+ this . renderActiveSortButton ( ) ;
59+ }
60+
61+ renderSizeOptions ( ) {
62+ this . refs . userSwatchSizeSelect . replaceChildren ( ) ;
63+ this . app . getSwatchSizeOptions ( ) . forEach ( ( size ) => {
4564 const option = this . document . createElement ( "option" ) ;
46- option . value = mode . value ;
47- option . textContent = mode . label ;
48- this . refs . userPaletteSortSelect . appendChild ( option ) ;
65+ option . value = size . value ;
66+ option . textContent = size . label ;
67+ this . refs . userSwatchSizeSelect . appendChild ( option ) ;
68+ } ) ;
69+ }
70+
71+ renderActiveSortButton ( ) {
72+ const activeMode = this . app . getUserSortMode ( ) ;
73+ this . refs . userPaletteSortControls . querySelectorAll ( "[data-sort-mode]" ) . forEach ( ( button ) => {
74+ const isActive = button . dataset . sortMode === activeMode ;
75+ button . classList . toggle ( "is-active" , isActive ) ;
76+ button . setAttribute ( "aria-checked" , String ( isActive ) ) ;
4977 } ) ;
5078 }
5179}
0 commit comments