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

create spacer chip #1098

Merged
merged 7 commits into from
Apr 17, 2023
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
7 changes: 7 additions & 0 deletions docs/cards/chips.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ An light chip allows you to display light.

A menu chip allows you to open the drawer in mobile.

### Spacer chip

![Chip menu light](../images/chip-spacer-light.png)
![Chip menu dark](../images/chip-spacer-dark.png)

A spacer chip allows you to space chips apart.

### Template chip

![Chip template light](../images/chip-template-light.png)
Expand Down
Binary file added docs/images/chip-spacer-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/chip-spacer-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 18 additions & 12 deletions src/cards/chips-card/chips-card-chips-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,33 @@ export class ChipsCardEditorChips extends MushroomBaseElement {
<div class="special-row">
<div>
<span> ${this._renderChipLabel(chipConf)}</span>
<span class="secondary"
>${this._renderChipSecondary(chipConf)}</span
>
<span class="secondary">
${this._renderChipSecondary(chipConf)}
</span>
</div>
</div>
`}
${chipConf.type == "spacer"
? ""
: html`
<ha-icon-button
.label=${customLocalize(
"editor.chip.chip-picker.edit"
)}
class="edit-icon"
.index=${index}
@click=${this._editChip}
>
<ha-icon icon="mdi:pencil"></ha-icon>
</ha-icon-button>
`}
<ha-icon-button
.label=${customLocalize("editor.chip.chip-picker.clear")}
class="remove-icon"
.index=${index}
@click=${this._removeChip}
>
<ha-icon icon="mdi:close"></ha-icon
></ha-icon-button>
<ha-icon-button
.label=${customLocalize("editor.chip.chip-picker.edit")}
class="edit-icon"
.index=${index}
@click=${this._editChip}
>
<ha-icon icon="mdi:pencil"></ha-icon>
<ha-icon icon="mdi:close"></ha-icon>
</ha-icon-button>
</div>
`
Expand Down
6 changes: 6 additions & 0 deletions src/cards/chips-card/chips-card-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ const templateChipConfigStruct = object({
entity_id: optional(union([string(), array(string())])),
});

const spacerChipConfigStruct = object({
type: literal("spacer"),
});

const chipsConfigStruct = dynamic<any>((value) => {
if (value && typeof value === "object" && "type" in value) {
switch ((value as LovelaceChipConfig).type!) {
Expand All @@ -130,6 +134,8 @@ const chipsConfigStruct = dynamic<any>((value) => {
return lightChipConfigStruct;
case "template":
return templateChipConfigStruct;
case "spacer":
return spacerChipConfigStruct;
}
}
return object();
Expand Down
1 change: 1 addition & 0 deletions src/cards/chips-card/chips/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export { TemplateChip } from "./template-chip";
export { ConditionalChip } from "./conditional-chip";
export { LightChip } from "./light-chip";
export { AlarmControlPanelChip } from "./alarm-control-panel-chip";
export { SpacerChip } from "./spacer-chip";
17 changes: 17 additions & 0 deletions src/cards/chips-card/chips/spacer-chip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { css, CSSResultGroup, LitElement } from "lit";
import { customElement } from "lit/decorators.js";
import { LovelaceChip } from "../../../utils/lovelace/chip/types";
import { computeChipComponentName } from "../../../utils/lovelace/chip/chip-element";

@customElement(computeChipComponentName("spacer"))
export class SpacerChip extends LitElement implements LovelaceChip {
public setConfig(): void {}

static get styles(): CSSResultGroup {
return css`
:host {
flex-grow: 1;
}
`;
}
}
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"entity": "Entity",
"light": "Light",
"menu": "Menu",
"spacer": "Spacer",
"template": "Template",
"weather": "Weather"
}
Expand Down
8 changes: 7 additions & 1 deletion src/utils/lovelace/chip/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ export type LightChipConfig = {
double_tap_action?: ActionConfig;
};

export type SpacerChipConfig = {
type: "spacer";
};

export type LovelaceChipConfig =
| ActionChipConfig
| AlarmControlPanelChipConfig
Expand All @@ -101,7 +105,8 @@ export type LovelaceChipConfig =
| WeatherChipConfig
| TemplateChipConfig
| ConditionalChipConfig
| LightChipConfig;
| LightChipConfig
| SpacerChipConfig;

export const CHIP_LIST: LovelaceChipConfig["type"][] = [
"action",
Expand All @@ -111,6 +116,7 @@ export const CHIP_LIST: LovelaceChipConfig["type"][] = [
"entity",
"light",
"menu",
"spacer",
"template",
"weather",
];