Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: InlineSelect ability #5963

Merged
merged 11 commits into from
Oct 6, 2023
12 changes: 12 additions & 0 deletions components/Common/Select/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
dark:focus:border-neutral-600
dark:focus:ring-neutral-600
dark:data-[placeholder]:text-neutral-200;

& span {
@apply flex
items-center
gap-2;
}
}

.icon {
Expand Down Expand Up @@ -75,6 +81,12 @@
data-[highlighted]:outline-none
dark:text-neutral-200
dark:data-[highlighted]:bg-green-600;

& span {
@apply flex
items-center
gap-2;
}
}

.label {
Expand Down
34 changes: 34 additions & 0 deletions components/Common/Select/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,38 @@ export const DropdownLabel: Story = {
},
};

export const InlineSelect: Story = {
args: {
values: [
{
value: 'ubuntu',
label: 'Ubuntu',
iconImageUrl: '/static/images/logos/platform-linux.svg',
},
{
value: 'apple',
label: 'Apple',
iconImageUrl: '/static/images/logos/platform-apple.svg',
},
{
value: 'microsoft',
label: 'Microsoft',
iconImageUrl: '/static/images/logos/platform-microsoft.svg',
},
{
value: 'homebrew',
label: 'Homebrew',
iconImageUrl: '/static/images/logos/platform-homebrew.svg',
},
{
value: 'placeholder',
label: 'Placeholder',
iconImageUrl: '/static/images/logos/platform-placeholder.svg',
},
],
dropdownLabel: 'Platform',
placeholder: 'Select a platform',
},
};

export default { component: Select } as Meta;
17 changes: 14 additions & 3 deletions components/Common/Select/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ChevronDownIcon } from '@heroicons/react/24/outline';
import * as Primitive from '@radix-ui/react-select';
import Image from 'next/image';
import { useId } from 'react';
import type { FC } from 'react';

import styles from './index.module.css';

type SelectProps = {
values: ({ label: string; value: string } | string)[];
values: ({ label: string; value: string; iconImageUrl?: string } | string)[];
canerakdas marked this conversation as resolved.
Show resolved Hide resolved
defaultValue?: string;
placeholder?: string;
dropdownLabel?: string;
Expand Down Expand Up @@ -34,7 +35,7 @@ const Select: FC<SelectProps> = ({
<Primitive.Root defaultValue={defaultValue} onValueChange={onChange}>
<Primitive.Trigger
className={styles.trigger}
aria-label={label}
aria-label={label || dropdownLabel}
id={id}
>
<Primitive.Value placeholder={placeholder} />
Expand All @@ -59,7 +60,17 @@ const Select: FC<SelectProps> = ({
value={value}
className={`${styles.item} ${styles.text}`}
>
<Primitive.ItemText>{label}</Primitive.ItemText>
<Primitive.ItemText>
{typeof item !== 'string' && item.iconImageUrl && (
canerakdas marked this conversation as resolved.
Show resolved Hide resolved
<Image
src={item.iconImageUrl}
alt={label}
width={16}
height={16}
/>
)}
{label}
</Primitive.ItemText>
</Primitive.Item>
);
})}
Expand Down
Loading