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

chore: checkbox light mode #7165

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/main/src/plugin/color-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export class ColorRegistry {
this.initInvertContent();
this.initCardContent();
this.initInputBox();
this.initCheckbox();
}

protected initGlobalNav(): void {
Expand Down Expand Up @@ -543,4 +544,38 @@ export class ColorRegistry {
light: colorPalette.gray[500],
});
}

// chexkboxes
protected initCheckbox(): void {
const sNav = 'input-checkbox-';

this.registerColor(`${sNav}disabled`, {
dark: colorPalette.charcoal[300],
light: colorPalette.charcoal[300],
});
this.registerColor(`${sNav}indeterminate`, {
dark: colorPalette.dustypurple[500],
light: colorPalette.dustypurple[500],
});
this.registerColor(`${sNav}focused-indeterminate`, {
dark: colorPalette.dustypurple[400],
light: colorPalette.dustypurple[600],
});
this.registerColor(`${sNav}checked`, {
dark: colorPalette.purple[500],
light: colorPalette.purple[500],
});
this.registerColor(`${sNav}focused-checked`, {
dark: colorPalette.purple[400],
light: colorPalette.purple[600],
});
this.registerColor(`${sNav}unchecked`, {
dark: colorPalette.gray[400],
light: colorPalette.charcoal[700],
});
this.registerColor(`${sNav}focused-unchecked`, {
dark: colorPalette.purple[500],
light: colorPalette.purple[500],
});
}
}
49 changes: 49 additions & 0 deletions packages/ui/src/lib/checkbox/Checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,51 @@ test('Basic check', async () => {
const checkbox = screen.getByRole('checkbox');
expect(checkbox).toBeInTheDocument();
expect(checkbox).toBeEnabled();

const peer = getPeer(checkbox);
expect(peer).toBeInTheDocument();
expect(peer).toHaveClass('cursor-pointer');

const icon = peer?.children[0];
expect(icon).toBeInTheDocument();
expect(icon).toHaveClass('text-[var(--pd-input-checkbox-unchecked)]');
expect(icon).toHaveClass('hover:text-[var(--pd-input-checkbox-focused-unchecked)]');
});

test('Check checked state', async () => {
render(Checkbox, { checked: true });

// check element exists and is enabled
const checkbox = screen.getByRole('checkbox');
expect(checkbox).toBeInTheDocument();
expect(checkbox).toBeEnabled();

const peer = getPeer(checkbox);
expect(peer).toBeInTheDocument();
expect(peer).toHaveClass('cursor-pointer');

const icon = peer?.children[0];
expect(icon).toBeInTheDocument();
expect(icon).toHaveClass('text-[var(--pd-input-checkbox-checked)]');
expect(icon).toHaveClass('hover:text-[var(--pd-input-checkbox-focused-checked)]');
});

test('Check indeterminate state', async () => {
render(Checkbox, { indeterminate: true });

// check element exists and is enabled
const checkbox = screen.getByRole('checkbox');
expect(checkbox).toBeInTheDocument();
expect(checkbox).toBeEnabled();

const peer = getPeer(checkbox);
expect(peer).toBeInTheDocument();
expect(peer).toHaveClass('cursor-pointer');

const icon = peer?.children[0];
expect(icon).toBeInTheDocument();
expect(icon).toHaveClass('text-[var(--pd-input-checkbox-indeterminate)]');
expect(icon).toHaveClass('hover:text-[var(--pd-input-checkbox-focused-indeterminate)]');
});

test('Check disabled state', async () => {
Expand All @@ -50,6 +95,10 @@ test('Check disabled state', async () => {
const peer = getPeer(checkbox);
expect(peer).toBeInTheDocument();
expect(peer).toHaveClass('cursor-not-allowed');

const icon = peer?.children[0];
expect(icon).toBeInTheDocument();
expect(icon).toHaveClass('text-[var(--pd-input-checkbox-disabled)]');
});

test('Check tooltips', async () => {
Expand Down
17 changes: 13 additions & 4 deletions packages/ui/src/lib/checkbox/Checkbox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ function onClick(
class:cursor-pointer="{!disabled}"
class:cursor-not-allowed="{disabled}">
{#if disabled}
<Fa size="1.1x" icon="{faSquare}" class="text-charcoal-300" />
<Fa size="1.1x" icon="{faSquare}" class="text-[var(--pd-input-checkbox-disabled)]" />
{:else if indeterminate}
<Fa size="1.1x" icon="{faMinusSquare}" class="text-dustypurple-500" />
<Fa
size="1.1x"
icon="{faMinusSquare}"
class="text-[var(--pd-input-checkbox-indeterminate)] hover:text-[var(--pd-input-checkbox-focused-indeterminate)]" />
{:else if checked}
<Fa size="1.1x" icon="{faCheckSquare}" class="text-purple-500" />
<Fa
size="1.1x"
icon="{faCheckSquare}"
class="text-[var(--pd-input-checkbox-checked)] hover:text-[var(--pd-input-checkbox-focused-checked)]" />
{:else}
<Fa size="1.1x" icon="{faOutlineSquare}" class="text-gray-400" />
<Fa
size="1.1x"
icon="{faOutlineSquare}"
class="text-[var(--pd-input-checkbox-unchecked)] hover:text-[var(--pd-input-checkbox-focused-unchecked)]" />
{/if}
</div>
<input
Expand Down