Skip to content

feat(uui-card): Adds checkbox for selection #1138

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class UUICardBlockTypeElement extends UUICardElement {
${this.href ? this.#renderLink() : this.#renderButton()}
<!-- Select border must be right after #open-part -->
<div id="select-border"></div>

${this.selectable ? this.renderCheckbox() : nothing}
<slot name="tag"></slot>
<slot name="actions"></slot>
`;
Expand Down
11 changes: 8 additions & 3 deletions packages/uui-card-block-type/lib/uui-card-block-type.story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ export const Background: Story = {

export const Image: Story = {
args: {
slot: html`<img
src="https://umbraco.com/media/v5gf3w2a/umbraco-toolkit-wide.svg"
alt="" />`,
slot: html`<img src="https://placedog.net/1447/?random" alt="" />`,
},
};

export const Selectable: Story = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the case I'm most concerned about in general is the selectable but not select-only. That is the most common case in the CMS.
So to ensure devs test that case, I would like that to have a story, which leads me to think if this one should be called Only Selectable

and then have one called Selectable, but that does not have selectOnly toggled on :-)

args: {
selectable: true,
selectOnly: true,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class UUICardContentNodeElement extends UUICardElement {
${this.href ? this.#renderLink() : this.#renderButton()}
<!-- Select border must be right after #open-part -->
<div id="select-border"></div>

${this.selectable ? this.renderCheckbox() : nothing}
<slot name="tag"></slot>
<slot name="actions"></slot>
`;
Expand Down Expand Up @@ -226,6 +226,11 @@ export class UUICardContentNodeElement extends UUICardElement {
:host(:not([disabled])) #open-part:hover #default {
color: var(--uui-color-interactive-emphasis);
}

#select-checkbox {
top: var(--uui-size-5);
left: var(--uui-size-6);
}
`,
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ export const CustomIcon: Story = {
'icon slot': html`<uui-icon slot="icon" name="wand"></uui-icon>`,
},
};

export const Selectable: Story = {
args: {
selectable: true,
selectOnly: true,
},
};
3 changes: 1 addition & 2 deletions packages/uui-card-media/lib/uui-card-media.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class UUICardMediaElement extends UUICardElement {
${this.href ? this.#renderLink() : this.#renderButton()}
<!-- Select border must be right after .open-part -->
<div id="select-border"></div>

${this.selectable ? this.renderCheckbox() : nothing}
<slot name="tag"></slot>
<slot name="actions"></slot>`;
}
Expand Down Expand Up @@ -208,7 +208,6 @@ export class UUICardMediaElement extends UUICardElement {
#content {
position: relative;
display: flex;
width: 100%;
flex-direction: column;
font-family: inherit;
box-sizing: border-box;
Expand Down
7 changes: 7 additions & 0 deletions packages/uui-card-media/lib/uui-card-media.story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,10 @@ export const Image: Story = {
chromatic: { disableSnapshot: true },
},
};

export const Selectable: Story = {
args: {
selectable: true,
selectOnly: true,
},
};
1 change: 1 addition & 0 deletions packages/uui-card-user/lib/uui-card-user.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class UUICardUserElement extends UUICardElement {
${this.href ? this.#renderLink() : this.#renderButton()}
<!-- Select border must be right after #open-part -->
<div id="select-border"></div>
${this.selectable ? this.renderCheckbox() : nothing}
<slot name="tag"></slot>
<slot name="actions"></slot>
`;
Expand Down
7 changes: 7 additions & 0 deletions packages/uui-card-user/lib/uui-card-user.story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ export const Actions: Story = {
>`,
},
};

export const Selectable: Story = {
args: {
selectable: true,
selectOnly: true,
},
};
30 changes: 30 additions & 0 deletions packages/uui-card/lib/uui-card.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { property } from 'lit/decorators.js';

import { UUICardEvent } from './UUICardEvent';

import '@umbraco-ui/uui-checkbox/lib';

/**
* Card is a Component that provides the basics for a Card component. This can be extended in code to match a certain need.
* @element uui-card
Expand Down Expand Up @@ -83,6 +85,19 @@ export class UUICardElement extends SelectOnlyMixin(
this.dispatchEvent(new UUICardEvent(UUICardEvent.OPEN));
}

protected renderCheckbox() {
if (!this.selectable) return;
return html`
<uui-checkbox
id="select-checkbox"
label="select"
?checked=${this.selected}
@click=${(e: MouseEvent) => e.stopPropagation()}
@change=${() => this.click()}>
</uui-checkbox>
`;
}

protected render() {
return html`<slot id="open-part"></slot>
<div id="select-border"></div>`;
Expand Down Expand Up @@ -236,6 +251,21 @@ export class UUICardElement extends SelectOnlyMixin(
background: var(--uui-color-disabled);
color: var(--uui-color-disabled-contrast);
}

#select-checkbox {
position: absolute;
top: var(--uui-size-4);
left: var(--uui-size-4);
opacity: 0;
transition: opacity 120ms;
z-index: 3;
}
:host(:focus) #select-checkbox,
:host(:focus-within) #select-checkbox,
:host(:hover) #select-checkbox,
#select-checkbox[checked] {
opacity: 1;
}
`,
];
}
Expand Down
3 changes: 2 additions & 1 deletion packages/uui-card/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"custom-elements.json"
],
"dependencies": {
"@umbraco-ui/uui-base": "1.14.1"
"@umbraco-ui/uui-base": "1.14.1",
"@umbraco-ui/uui-checkbox": "1.14.1"
},
"scripts": {
"build": "npm run analyze && tsc --build && rollup -c rollup.config.js",
Expand Down
3 changes: 3 additions & 0 deletions packages/uui-card/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"references": [
{
"path": "../uui-base"
},
{
"path": "../uui-checkbox"
}
]
}
Loading