Skip to content

Commit

Permalink
docs: adjust select width in appearance demos based on content (#4085)
Browse files Browse the repository at this point in the history
* docs: adjust select width in appearance demos based on content

* make it a bit bigger

* ???

* remove log
  • Loading branch information
sebald authored Aug 6, 2024
1 parent 3ea6f99 commit fd314e5
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions docs/ui/AppearanceDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@ import { useState } from 'react';
import { Info } from '@marigold/icons';
import { useThemeSwitch } from '@/ui/ThemeSwitch';

// Helpers
// ---------------
function getLongestString(list: string[]) {
const sortedArray = list.sort((a, b) => b.length - a.length);
return sortedArray[0];
}

const getSelectWidth = (options: string[]) => {
const length = (getLongestString(options) || '').length;

// Poor mans pattern matching
switch (true) {
case length < 10:
return 40;
case length >= 10 && length < 12:
return 44;
case length >= 12 && length < 14:
return 48;
default:
return 52;
}
};

// Props
// ---------------
export interface AppearanceDemoProps {
Expand Down Expand Up @@ -76,7 +99,7 @@ export const AppearanceDemo = ({
label="Variant"
variant="floating"
size="small"
width={36}
width={getSelectWidth(appearance.variant)}
selectedKey={selected.variant}
onChange={(val: string) =>
setSelected({ variant: val, size: selected.size })
Expand All @@ -94,7 +117,7 @@ export const AppearanceDemo = ({
label="Size"
variant="floating"
size="small"
width={32}
width={getSelectWidth(appearance.size)}
selectedKey={selected.size}
onChange={(val: string) =>
setSelected({ variant: selected.variant, size: val })
Expand All @@ -109,7 +132,7 @@ export const AppearanceDemo = ({
))}
</Select>
{isVariantOrSizeMissing ? (
<div className="flex items-center gap-2 text-xs">
<div className="text-text-primary-muted flex items-center gap-0.5 text-xs">
<Info size={14} />
There is currently no available option for {disabledAppearance} to
select.
Expand Down

0 comments on commit fd314e5

Please sign in to comment.