Skip to content

Commit

Permalink
Remove hardcoded http. Isolate some css. Adds dark-mode. Adds audible.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Kristian Nilsen committed Mar 6, 2024
1 parent 50d99bd commit d5b1da4
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 192 deletions.
118 changes: 67 additions & 51 deletions dist/mediatracker-card.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
"build": "rollup -c --bundleConfigAsCjs",
"dev": "rollup -c --watch --bundleConfigAsCjs"
}
}
}
118 changes: 5 additions & 113 deletions src/styles/card.ts
Original file line number Diff line number Diff line change
@@ -1,120 +1,12 @@
import { css } from "lit";

export const cardStyle = css`
// Card
.mt-card {
display: flex;
flex-direction: column;
padding: 1rem;
:root {
--dark-primary-color: #0288d1;
--light-primary-color: #b3e5fC;
}
.mt-header {
color: var(--ha-card-header-color,--primary-text-color);
font-size: var(--ha-card-header-font-size,24px);
padding-block: .5rem;
margin-bottom: 1rem;
}
.mt-calendar.constrict {
overflow-y: scroll;
max-height: 450px;
padding-right: 1rem;
}
.mt-day {
margin-bottom: 1.6rem;
}
// Events
.mt-events-header {
display: flex;
flex-direction: row;
justify-content: space-between;
border-bottom: 1px solid var(--divider-color);
margin-bottom: 1rem;
padding-bottom: .5rem;
}
.mt-events-header__day,
.mt-events-header__date {
font-size: 18px;
font-weight: 400;
padding: 0;
margin: 0;
}
.mt-events {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
grid-auto-rows: 1fr;
gap: 1rem;
}
// Event
.mt-event {
position: relative;
border-radius: 10px;
height: 100%;
overflow: hidden;
/* white-space: nowrap; */
}
.mt-event-backdrop {
position: absolute;
object-fit: cover;
width: 100%;
height: 100%;
object-position: center;
}
.mt-event-content {
position: relative;
z-index: 2;
color: var(--primary-text-color);
font-weight: 400;
display: flex;
flex-direction: column;
gap: 1rem;
}
.has-backdrop .mt-event-content {
background-color: rgba(0,0,0,.75);
padding: 1rem;
height: 100%;
}
.mt-event-title {
font-size: 14px;
font-weight: 400;
position: relative;
color: var(--primary-text-color);
margin: 0;
margin-left: 5px;
&:before {
content: "";
display: inline-block;
background-color: var(--event-bg);
width: 10px;
height: 10px;
border-radius: 100%;
transform: translateX(-5px);
}
}
.has-backdrop .mt-event-title {
font-weight: 500;
}
.mt-event-description {
color: var(--secondary-text-color);
font-size: 13px;
margin-bottom: 1rem;
}
.has-backdrop .mt-event-description {
color: var(--primary-text-color);
margin-bottom: 0;
max-width: 600px;
a {
color: var(--mt-link-color);
}
`;
13 changes: 9 additions & 4 deletions src/templates/event-backdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ dayjs.extend(updateLocale);
dayjs.extend(relativeTime);
import setupCustomlocalize from "../localize/localize";
import { getSourceLinks } from "../utils";
import { cardStyle } from "../styles/card";

@customElement("mediatracker-event-backdrop")
export class MediaTrackerCardEvent extends LitElement {
@property() hass;
@property() event;
@property() rating;
@property() dark_mode;
@property() description;
@property() source_links;

Expand All @@ -34,7 +36,7 @@ export class MediaTrackerCardEvent extends LitElement {
}

return html`
<div class="mt-event" style="--event-color: ${this.event.backgroundColor}; --event-backdrop: url(http://${data.host}${data.backdrop}?token=${data.token})">
<div class="mt-event" style="--event-color: ${this.event.backgroundColor}; --event-backdrop: url(//${data.host}${data.backdrop}?token=${data.token})">
<span class="mt-event-color" style="--event-color: ${this.event.backgroundColor};"></span>
<div class="mt-event-content">
<header class="mt-event-header">
Expand All @@ -56,7 +58,9 @@ export class MediaTrackerCardEvent extends LitElement {
}

static get styles(): CSSResultGroup {
return css`
return [
cardStyle,
css`
.mt-event {
background-color: var(--event-color);
background-image: var(--event-backdrop);
Expand Down Expand Up @@ -119,9 +123,10 @@ export class MediaTrackerCardEvent extends LitElement {
margin: 0;
font-size: 13px;
padding-block: .5rem;
color: var(--primary-text-color);
color: var(--secondary-text-color);
max-width: 600px;
}
`;
`
]
}
}
14 changes: 9 additions & 5 deletions src/templates/event-poster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class MediaTrackerCardEvent extends LitElement {
return html`
<div class="mt-event" style="--event-color: ${this.event.backgroundColor};">
<figure class="mt-event-poster">
<img src="http://${data.host}${data.poster}?size=small&token=${data.token}">
<img src="//${data.host}${data.poster}?size=small&token=${data.token}">
</figure>
<div class="mt-event-content">
Expand Down Expand Up @@ -69,6 +69,10 @@ export class MediaTrackerCardEvent extends LitElement {
overflow: hidden;
}
.mt-event a {
color: var(--event-color);
}
.mt-event-icon {
--mdc-icon-size: 20px;
}
Expand All @@ -86,13 +90,13 @@ export class MediaTrackerCardEvent extends LitElement {
}
.mt-event-content {
color: var(--primary-text-color);
color: var(--light-primary-color);
padding-left: 1rem;
font-weight: 400;
display: flex;
flex-direction: column;
gap: .3rem;
background-color: rgba(0,0,0,.6);
background-color: rgba(0,0,0,.7);
padding: 1rem;
height: 100%;
}
Expand All @@ -110,7 +114,7 @@ export class MediaTrackerCardEvent extends LitElement {
margin: 0;
font-size: 16px;
font-weight: 500;
color: var(--primary-text-color);
color: var(--light-primary-color);
}
.mt-event-details {
Expand All @@ -125,7 +129,7 @@ export class MediaTrackerCardEvent extends LitElement {
margin: 0;
font-size: 13px;
padding-block: .5rem;
color: var(--primary-text-color);
color: var(--light-primary-color);
max-width: 600px;
}
`;
Expand Down
2 changes: 1 addition & 1 deletion src/templates/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class MediaTrackerCardEvent extends LitElement {
margin: 0;
font-size: 13px;
padding-block: .5rem;
color: var(--primary-text-color);
color: var(--secondary-text-color);
max-width: 600px;
}
`;
Expand Down
2 changes: 2 additions & 0 deletions src/templates/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class MediaTrackerCardEvents extends LitElement {
return html``;
}

const darkMode = this.hass.themes.darkMode;
const customLocalize = setupCustomlocalize(this.hass!);

return html`
Expand All @@ -48,6 +49,7 @@ export class MediaTrackerCardEvents extends LitElement {
<mediatracker-event-backdrop
.hass=${this.hass}
.event="${event}"
.dark_mode="${darkMode}"
.rating="${this.config.show_rating}"
.description="${this.config.description}"
.source_links="${this.config.source_links}"
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface MediaTrackerCalendarEvent {
}

export interface MediaTrackerCalendarEventSources {
audible?: string;
igdb?: string;
tmdb?: string;
imdb?: string;
Expand Down
24 changes: 7 additions & 17 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,30 +178,20 @@ export function getColorByIndex(index: number) {
return COLORS[index % COLORS.length];
}

export function getGraphColorByIndex(
index: number,
style: CSSStyleDeclaration
) {
// The CSS vars for the colors use range 1..n, so we need to adjust the index from the internal 0..n color index range.
return (
style.getPropertyValue(`--graph-color-${index + 1}`) ||
getColorByIndex(index)
);
}


export function getSourceLinks(type: string, sources: MediaTrackerCalendarEventSources) {
if(type == 'all') {
return html`
${sources.igdb ? html`<a class="mt-event-source" href="${sources.igdb}">IGDB</a>`:''}
${sources.tmdb ? html`<a class="mt-event-source" href="${sources.tmdb}">TMDB</a>`:''}
${sources.imdb ? html`<a class="mt-event-source" href="${sources.imdb}">IMDB</a>`:''}
${sources.audible ? html`<a class="mt-event-source" href="${sources.audible}" target="_new" title="Audible">Audible</a>`:''}
${sources.igdb ? html`<a class="mt-event-source" href="${sources.igdb}" target="_new" title="IGDB">IGDB</a>`:''}
${sources.tmdb ? html`<a class="mt-event-source" href="${sources.tmdb}" target="_new" title="TMDB">TMDB</a>`:''}
${sources.imdb ? html`<a class="mt-event-source" href="${sources.imdb}" target="_new" title="IMDB">IMDB</a>`:''}
`
}
if(type == 'primary') {
return html`
${sources.igdb ? html`<a class="mt-event-source" href="${sources.igdb}">IGDB</a>`:''}
${sources.tmdb ? html`<a class="mt-event-source" href="${sources.tmdb}">TMDB</a>`:''}
${sources.audible ? html`<a class="mt-event-source" href="${sources.audible}" target="_new" title="Audible">Audible</a>`:''}
${sources.igdb ? html`<a class="mt-event-source" href="${sources.igdb}" target="_new" title="IGDB">IGDB</a>`:''}
${sources.tmdb ? html`<a class="mt-event-source" href="${sources.tmdb}" target="_new" title="TMDB">TMDB</a>`:''}
`
}
return html``;
Expand Down

0 comments on commit d5b1da4

Please sign in to comment.