Skip to content

✨ feat: filter component #213

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

Merged
merged 10 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ module.exports = {
'warn',
{ allowConstantExport: true },
],
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
},
};
4 changes: 4 additions & 0 deletions lib/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ export const TextButton: Story = {
</Button>

<Button variant="text" theme="civo" disabled>
Text Civo Disabled
</Button>

<Button variant="text" disabled>
Text Disabled
</Button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/components/Button/Button.variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const buttonVariants = cva(
'colony:text-zinc-400',
'civo:bg-white',
'civo:border-white',
'civo:text-zinc-400',
'civo:text-civo-primary/45',
],
},
{
Expand Down
15 changes: 10 additions & 5 deletions lib/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ export const Checkbox: FC<CheckboxProps> = forwardRef<
title,
variant,
onChange,
...delegated
},
ref,
) => {
const [checked, setChecked] = useToggle(defaultChecked);
const [checked, setChecked] = useToggle(defaultChecked ?? false);
const defaultId = useId();

const handleChange = useCallback(() => {
setChecked();
onChange?.();
}, [onChange, setChecked]);
const handleChange = useCallback(
(checked: boolean) => {
setChecked(checked);
onChange?.(checked);
},
[onChange, setChecked],
);

return (
<div className="flex items-center gap-2" data-theme={theme}>
Expand All @@ -56,6 +60,7 @@ export const Checkbox: FC<CheckboxProps> = forwardRef<
}),
)}
onCheckedChange={handleChange}
{...delegated}
>
<Indicator>
<Check className="w-4 h-4 stroke-2" />
Expand Down
8 changes: 4 additions & 4 deletions lib/components/Checkbox/Checkbox.types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CheckboxProps as CheckboxPropsPrimitive } from '@radix-ui/react-checkbox';
import { VariantProps } from 'class-variance-authority';
import { InputHTMLAttributes } from 'react';

import { Theme } from '@/domain/theme';
import { checkboxVariants } from './Checkbox.variants';

export interface CheckboxProps
extends Omit<InputHTMLAttributes<HTMLInputElement>, 'checked'>,
VariantProps<typeof checkboxVariants> {
extends Omit<CheckboxPropsPrimitive, 'onChange'>,
Omit<VariantProps<typeof checkboxVariants>, 'checked'> {
ariaLabelledBy?: string;
className?: string;
defaultChecked?: boolean;
Expand All @@ -16,5 +16,5 @@ export interface CheckboxProps
labelClassName?: string;
name?: string;
theme?: Theme;
onChange?: () => void;
onChange?: (checked: boolean) => void;
}
4 changes: 2 additions & 2 deletions lib/components/Checkbox/Checkbox.variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const checkboxVariants = cva(
'text-white',
'border-kubefirst-primary',
'colony:border-red-700',
'civo:border-civo-primary',
'civo:border-zinc-400',
],
{
variants: {
Expand All @@ -32,7 +32,7 @@ export const checkboxVariants = cva(
class: [
'bg-kubefirst-primary',
'colony:bg-red-700',
'civo:bg-civo-primary',
['civo:bg-civo-primary', 'civo:border-civo-primary'],
],
},
],
Expand Down
16 changes: 13 additions & 3 deletions lib/components/Datepicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ const DatePicker: FC<DatePickerProps> = ({
className,
showOutsideDays = true,
animate = true,
arrowClassName,
monthsClassName,
defaultSelected,
onSelect,
...delegated
}) => {
const [selected, setSelected] = useState<Date>();
const [selected, setSelected] = useState<Date | undefined>(
() => defaultSelected,
);

const handleSelect = useCallback(
(date?: Date) => {
Expand Down Expand Up @@ -47,10 +52,15 @@ const DatePicker: FC<DatePickerProps> = ({
day: 'text-center text-[14px] leading-[20px]',
month_caption:
'text-slate-700 font-semibold text-sm pl-1 h-[32px] flex items-center',
months:
months: cn(
'flex flex-col relative px-5 py-4 rounded-lg shadow-md px-6 py-4 w-[307px] justify-center items-center',
monthsClassName,
),
month: 'flex flex-col gap-4',
nav: 'absolute right-4 top-3.5 flex justify-center items-center gap-[4px]',
nav: cn(
'absolute right-4 top-3.5 flex justify-center items-center gap-[4px]',
arrowClassName,
),
outside: 'text-slate-400',
selected:
'[&>button]:bg-blue-600 [&>button]:text-white [&>button]:hover:bg-blue-700 [&>button]:transition-all [&>button]:duration-300 [&>button]:rounded-full',
Expand Down
3 changes: 3 additions & 0 deletions lib/components/Datepicker/DatePicker.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ type TimeZone = keyof ReturnType<typeof getAllTimezones>;

export type DatePickerProps = Omit<DayPickerPrimitiveProps, 'mode'> &
VariantProps<typeof datePickerVariants> & {
arrowClassName?: string;
monthsClassName?: string;
timeZone?: TimeZone;
defaultSelected?: Date;
onSelect?: (date: Date) => void;
};
82 changes: 82 additions & 0 deletions lib/components/Filter/Filter.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import { useMemo, useState } from 'react';

import { Filter as FilterComponent } from './Filter';
import { Option } from './Filter.types';

type Story = StoryObj<typeof FilterComponent>;

const meta: Meta<typeof FilterComponent> = {
title: 'In Review/Filter',
component: FilterComponent,
};

export const Filter: Story = {
render: (args) => {
const [selectedStatus, setSelectedStatus] = useState<Option[]>([]);
const [date, setDate] = useState<Date | undefined>();

const onApplyDate = (date?: Date) => setDate(date);

const onApplyBadge = (selectedOptions: Option[]) => {
setSelectedStatus(selectedOptions);
};

const options = useMemo<Option[]>(
() => [
{
id: 'creating',
label: 'Creating',
variant: 'warning',
},
{
id: 'deleting',
label: 'Deleting',
variant: 'danger',
},
{
id: 'failed',
label: 'Failed',
variant: 'danger',
},
{
id: 'pending',
label: 'Pending',
variant: 'info',
},
{
id: 'ready',
label: 'Ready',
variant: 'success',
},
{
id: 'retrying',
label: 'Retrying',
variant: 'warning',
},
],
[],
);

return (
<div className="max-w-[350px] flex flex-col gap-2">
<FilterComponent {...args}>
<FilterComponent.BadgeMultiSelect
label="Status"
options={options}
onApply={onApplyBadge}
/>
<FilterComponent.DateFilterDropdown
label="Created"
onApply={onApplyDate}
/>
<FilterComponent.ResetButton
disabled={!date && selectedStatus.length === 0}
/>
</FilterComponent>
</div>
);
},
};

export default meta;
Loading