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 12 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.

18 changes: 8 additions & 10 deletions packages/uui-card-block-type/lib/uui-card-block-type.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@ 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>
`;
}

#renderButton() {
const tabIndex = !this.disabled ? (this.selectOnly ? -1 : 0) : undefined;
return html`
<button
id="open-part"
class="uui-text"
tabindex=${this.disabled ? (nothing as any) : '0'}
tabindex=${ifDefined(tabIndex)}
@click=${this.handleOpenClick}
@keydown=${this.handleOpenKeydown}>
${this.#renderContent()}
Expand All @@ -69,19 +70,16 @@ export class UUICardBlockTypeElement extends UUICardElement {
}

#renderLink() {
const tabIndex = !this.disabled ? (this.selectOnly ? -1 : 0) : undefined;
const rel = this.target === '_blank' ? 'noopener noreferrer' : undefined;
return html`
<a
id="open-part"
class="uui-text"
tabindex=${this.disabled ? (nothing as any) : '0'}
tabindex=${ifDefined(tabIndex)}
href=${ifDefined(!this.disabled ? this.href : undefined)}
target=${ifDefined(this.target || undefined)}
rel=${ifDefined(
this.rel ||
ifDefined(
this.target === '_blank' ? 'noopener noreferrer' : undefined,
),
)}>
rel=${ifDefined(this.rel || rel)}>
${this.#renderContent()}
</a>
`;
Expand All @@ -97,7 +95,7 @@ export class UUICardBlockTypeElement extends UUICardElement {
return html`
<div id="content">
<span title="${this.name}" id="name">${this.name}</span>
<small title="${this.description}">${this.description}<slot name="description"></slot></small>
<small title="${ifDefined(this.description)}">${this.description}<slot name="description"></slot></small>
</div></div>
`;
}
Expand Down
17 changes: 14 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,19 @@ 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 = {
args: {
selectable: true,
},
};

export const OnlySelectable: Story = {
args: {
selectable: true,
selectOnly: true,
},
};
49 changes: 28 additions & 21 deletions packages/uui-card-content-node/lib/uui-card-content-node.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,37 +86,39 @@ export class UUICardContentNodeElement extends UUICardElement {
}

#renderButton() {
return html`<button
id="open-part"
tabindex=${this.disabled ? (nothing as any) : 0}
@click=${this.handleOpenClick}
@keydown=${this.handleOpenKeydown}>
${this.#renderContent()}
</button>`;
const tabIndex = !this.disabled ? (this.selectOnly ? -1 : 0) : undefined;
return html`
<button
id="open-part"
tabindex=${ifDefined(tabIndex)}
@click=${this.handleOpenClick}
@keydown=${this.handleOpenKeydown}>
${this.#renderContent()}
</button>
`;
}

#renderLink() {
return html`<a
id="open-part"
tabindex=${this.disabled ? (nothing as any) : 0}
href=${ifDefined(!this.disabled ? this.href : undefined)}
target=${ifDefined(this.target || undefined)}
rel=${ifDefined(
this.rel ||
ifDefined(
this.target === '_blank' ? 'noopener noreferrer' : undefined,
),
)}>
${this.#renderContent()}
</a>`;
const tabIndex = !this.disabled ? (this.selectOnly ? -1 : 0) : undefined;
const rel = this.target === '_blank' ? 'noopener noreferrer' : undefined;
return html`
<a
id="open-part"
tabindex=${ifDefined(tabIndex)}
href=${ifDefined(!this.disabled ? this.href : undefined)}
target=${ifDefined(this.target || undefined)}
rel=${ifDefined(this.rel || rel)}>
${this.#renderContent()}
</a>
`;
}

public render() {
return html`
${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 +228,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
13 changes: 13 additions & 0 deletions packages/uui-card-content-node/lib/uui-card-content-node.story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,16 @@ export const CustomIcon: Story = {
'icon slot': html`<uui-icon slot="icon" name="wand"></uui-icon>`,
},
};

export const Selectable: Story = {
args: {
selectable: true,
},
};

export const OnlySelectable: Story = {
args: {
selectable: true,
selectOnly: true,
},
};
17 changes: 7 additions & 10 deletions packages/uui-card-media/lib/uui-card-media.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ export class UUICardMediaElement extends UUICardElement {
}

#renderButton() {
const tabIndex = !this.disabled ? (this.selectOnly ? -1 : 0) : undefined;
return html`
<button
id="open-part"
tabindex=${this.disabled ? (nothing as any) : '0'}
tabindex=${ifDefined(tabIndex)}
@click=${this.handleOpenClick}
@keydown=${this.handleOpenKeydown}>
${this.#renderContent()}
Expand All @@ -83,18 +84,15 @@ export class UUICardMediaElement extends UUICardElement {
}

#renderLink() {
const tabIndex = !this.disabled ? (this.selectOnly ? -1 : 0) : undefined;
const rel = this.target === '_blank' ? 'noopener noreferrer' : undefined;
return html`
<a
id="open-part"
tabindex=${this.disabled ? (nothing as any) : '0'}
tabindex=${ifDefined(tabIndex)}
href=${ifDefined(!this.disabled ? this.href : undefined)}
target=${ifDefined(this.target || undefined)}
rel=${ifDefined(
this.rel ||
ifDefined(
this.target === '_blank' ? 'noopener noreferrer' : undefined,
),
)}>
rel=${ifDefined(this.rel || rel)}>
${this.#renderContent()}
</a>
`;
Expand All @@ -118,7 +116,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 +206,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
13 changes: 13 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,16 @@ export const Image: Story = {
chromatic: { disableSnapshot: true },
},
};

export const Selectable: Story = {
args: {
selectable: true,
},
};

export const OnlySelectable: Story = {
args: {
selectable: true,
selectOnly: true,
},
};
73 changes: 39 additions & 34 deletions packages/uui-card-user/lib/uui-card-user.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,53 +40,58 @@ export class UUICardUserElement extends UUICardElement {
}

#renderButton() {
return html`<div
id="open-part"
tabindex=${this.disabled ? (nothing as any) : '0'}
@click=${this.handleOpenClick}
@keydown=${this.handleOpenKeydown}>
${this.#renderContent()}
</div>`;
const tabIndex = !this.disabled ? (this.selectOnly ? -1 : 0) : undefined;
return html`
<div
id="open-part"
tabindex=${ifDefined(tabIndex)}
@click=${this.handleOpenClick}
@keydown=${this.handleOpenKeydown}>
${this.#renderContent()}
</div>
`;
}

#renderLink() {
return html`<a
id="open-part"
tabindex=${this.disabled ? (nothing as any) : '0'}
href=${ifDefined(!this.disabled ? this.href : undefined)}
target=${ifDefined(this.target || undefined)}
rel=${ifDefined(
this.rel ||
ifDefined(
this.target === '_blank' ? 'noopener noreferrer' : undefined,
),
)}>
${this.#renderContent()}
</a>`;
const tabIndex = !this.disabled ? (this.selectOnly ? -1 : 0) : undefined;
const rel = this.target === '_blank' ? 'noopener noreferrer' : undefined;
return html`
<a
id="open-part"
tabindex=${ifDefined(tabIndex)}
href=${ifDefined(!this.disabled ? this.href : undefined)}
target=${ifDefined(this.target || undefined)}
rel=${ifDefined(this.rel || rel)}>
${this.#renderContent()}
</a>
`;
}

#renderContent() {
return html`<div id="content">
${this._avatarSlotHasContent
? nothing
: html`<uui-avatar
class="avatar"
name=${this.name}
size="m"></uui-avatar>`}
<slot
name="avatar"
class="avatar"
@slotchange=${this._avatarSlotChanged}></slot>
<span title="${this.name}">${this.name}</span>
<slot></slot>
</div>`;
return html`
<div id="content">
${this._avatarSlotHasContent
? nothing
: html`<uui-avatar
class="avatar"
name=${this.name}
size="m"></uui-avatar>`}
<slot
name="avatar"
class="avatar"
@slotchange=${this._avatarSlotChanged}></slot>
<span title="${this.name}">${this.name}</span>
<slot></slot>
</div>
`;
}

public render() {
return html`
${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
13 changes: 13 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,16 @@ export const Actions: Story = {
>`,
},
};

export const Selectable: Story = {
args: {
selectable: true,
},
};

export const OnlySelectable: Story = {
args: {
selectable: true,
selectOnly: true,
},
};
Loading
Loading