Skip to content

Commit

Permalink
fix: Replace max_height with height
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This entirely removes `min_height`, and replaces `max_height` with `height`. The behavior is obviously not exactly the same, but the prior behavior did not actually work correctly. CSS does not  limit the height of child elements that are `100%` of their parents height if the parent does not have an explicit height set (this caused spillage over the set max height). As such, it's simpler to just allow the user to set the actual height of the card should they need to do so, with a (hopefully) minor loss of flexibility.
  • Loading branch information
dermotduffy committed Sep 15, 2024
1 parent 9766185 commit d3b9c41
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 49 deletions.
14 changes: 6 additions & 8 deletions docs/configuration/dimensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ dimensions:
# [...]
```

| Option | Default | Description |
| ------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `aspect_ratio_mode` | `dynamic` | The aspect ratio mode to use. Acceptable values: `dynamic`, `static`, `unconstrained`. See below. |
| `aspect_ratio` | `16:9` | The aspect ratio to use. Acceptable values: `[W]:[H]` or `[W]/[H]`. See below. |
| `max_height` | `100vh` | The maximum allowable height for the card. Specified in [CSS units](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units). Generally users should not need to change this setting unless they have set an `unconstrained` aspect ratio. |
| `min_height` | `100px` | The minimum allowable height for the card. Specified in [CSS units](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units). Generally users should not need to change this setting. |
| Option | Default | Description |
| ------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `aspect_ratio_mode` | `dynamic` | The aspect ratio mode to use. Acceptable values: `dynamic`, `static`, `unconstrained`. See below. |
| `aspect_ratio` | `16:9` | The aspect ratio to use. Acceptable values: `[W]:[H]` or `[W]/[H]`. See below. |
| `height` | `auto` | The height for the card. Specified in [CSS units](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units). Generally users should not need to change this. |

### `aspect_ratio_mode`

Expand All @@ -42,6 +41,5 @@ dimensions:
dimensions:
aspect_ratio_mode: dynamic
aspect_ratio: 16:9
max_height: 100vh
min_height: 100px
height: auto
```
3 changes: 1 addition & 2 deletions src/card-controller/style-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ export class StyleManager {
const config = this._api.getConfigManager().getConfig();
if (config) {
const card = this._api.getCardElementManager().getElement();
card.style.setProperty('--frigate-card-min-height', config.dimensions.min_height);
card.style.setProperty('--frigate-card-max-height', config.dimensions.max_height);
card.style.setProperty('--frigate-card-height', config.dimensions.height);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/config/management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
CONF_CAMERAS_GLOBAL_JSMPEG,
CONF_CAMERAS_GLOBAL_PTZ,
CONF_CAMERAS_GLOBAL_WEBRTC_CARD,
CONF_DIMENSIONS_HEIGHT,
CONF_ELEMENTS,
CONF_LIVE_CONTROLS_THUMBNAILS_EVENTS_MEDIA_TYPE,
CONF_LIVE_CONTROLS_TIMELINE_EVENTS_MEDIA_TYPE,
Expand Down Expand Up @@ -878,4 +879,6 @@ const UPGRADES = [
typeof data === 'object' && data ? (data as RawFrigateCardConfig) : {},
);
},
upgradeMoveToWithOverrides('dimensions.max_height', CONF_DIMENSIONS_HEIGHT),
deleteWithOverrides('dimensions.min_height'),
];
6 changes: 2 additions & 4 deletions src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1856,8 +1856,7 @@ export type GalleryConfig = z.infer<typeof galleryConfigSchema>;
const dimensionsConfigDefault = {
aspect_ratio_mode: 'dynamic' as const,
aspect_ratio: [16, 9],
max_height: '100vh',
min_height: '100px',
height: 'auto',
};

export const dimensionsConfigSchema = z
Expand All @@ -1866,8 +1865,7 @@ export const dimensionsConfigSchema = z
.enum(['dynamic', 'static', 'unconstrained'])
.default(dimensionsConfigDefault.aspect_ratio_mode),
aspect_ratio: aspectRatioSchema.default(dimensionsConfigDefault.aspect_ratio),
max_height: z.string().default(dimensionsConfigDefault.max_height),
min_height: z.string().default(dimensionsConfigDefault.min_height),
height: z.string().default(dimensionsConfigDefault.height),
})
.default(dimensionsConfigDefault);

Expand Down
3 changes: 1 addition & 2 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ const CONF_DIMENSIONS = 'dimensions' as const;
export const CONF_DIMENSIONS_ASPECT_RATIO = `${CONF_DIMENSIONS}.aspect_ratio` as const;
export const CONF_DIMENSIONS_ASPECT_RATIO_MODE =
`${CONF_DIMENSIONS}.aspect_ratio_mode` as const;
export const CONF_DIMENSIONS_MAX_HEIGHT = `${CONF_DIMENSIONS}.max_height` as const;
export const CONF_DIMENSIONS_MIN_HEIGHT = `${CONF_DIMENSIONS}.min_height` as const;
export const CONF_DIMENSIONS_HEIGHT = `${CONF_DIMENSIONS}.height` as const;

export const CONF_OVERRIDES = 'overrides' as const;

Expand Down
6 changes: 2 additions & 4 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ import {
CONF_CAMERAS_ARRAY_WEBRTC_CARD_URL,
CONF_DIMENSIONS_ASPECT_RATIO,
CONF_DIMENSIONS_ASPECT_RATIO_MODE,
CONF_DIMENSIONS_MAX_HEIGHT,
CONF_DIMENSIONS_MIN_HEIGHT,
CONF_DIMENSIONS_HEIGHT,
CONF_IMAGE_ENTITY,
CONF_IMAGE_ENTITY_PARAMETERS,
CONF_IMAGE_MODE,
Expand Down Expand Up @@ -2805,8 +2804,7 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
this._aspectRatioModes,
)}
${this._renderStringInput(CONF_DIMENSIONS_ASPECT_RATIO)}
${this._renderStringInput(CONF_DIMENSIONS_MAX_HEIGHT)}
${this._renderStringInput(CONF_DIMENSIONS_MIN_HEIGHT)}
${this._renderStringInput(CONF_DIMENSIONS_HEIGHT)}
</div>`
: ''}
${this._renderOptionSetHeader(
Expand Down
3 changes: 1 addition & 2 deletions src/localize/languages/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@
"static": "Relació d'aspecte estàtica",
"unconstrained": "Relació d'aspecte sense restriccions"
},
"max_height": "Alçada màxima de la targeta en unitats CSS (p. ex., '100vh')",
"min_height": "Alçada mínima de la targeta en unitats CSS (p. ex., '100 px')"
"height": ""
},
"live": {
"auto_mute": "Silencia automàticament les càmeres en directe",
Expand Down
3 changes: 1 addition & 2 deletions src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@
"static": "Static aspect ratio",
"unconstrained": "Unconstrained aspect ratio"
},
"max_height": "Maximum card height in CSS units (e.g. '100vh')",
"min_height": "Minimum card height in CSS units (e.g. '100px')"
"height": "Card height in CSS units (e.g. '500px')"
},
"live": {
"auto_mute": "Automatically mute live cameras",
Expand Down
3 changes: 1 addition & 2 deletions src/localize/languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@
"static": "Rapport hauteur/largeur statique",
"unconstrained": "Rapport hauteur/largeur sans contrainte"
},
"max_height": "Hauteur maximale de la carte en unités CSS (par exemple '100vh')",
"min_height": "Hauteur minimale de la carte en unités CSS (par exemple « 100 px »)"
"height": ""
},
"live": {
"auto_mute": "Couper automatiquement le son des caméras en direct",
Expand Down
3 changes: 1 addition & 2 deletions src/localize/languages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@
"static": "Proporzioni statiche",
"unconstrained": "Proporzioni non vincolate"
},
"max_height": "",
"min_height": ""
"height": ""
},
"live": {
"auto_mute": "Muta automaticamente le telecamere in diretta",
Expand Down
3 changes: 1 addition & 2 deletions src/localize/languages/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@
"static": "Proporção estática",
"unconstrained": "Proporção irrestrita"
},
"max_height": "",
"min_height": ""
"height": ""
},
"live": {
"auto_mute": "Silenciar câmeras ao vivo automaticamente",
Expand Down
3 changes: 1 addition & 2 deletions src/localize/languages/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@
"static": "Proporção estática",
"unconstrained": "Proporção irrestrita"
},
"max_height": "",
"min_height": ""
"height": ""
},
"live": {
"auto_mute": "Silenciar câmeras ao vivo automaticamente",
Expand Down
9 changes: 2 additions & 7 deletions src/scss/card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
// keeping the background-color within the radius.
border-radius: var(--ha-card-border-radius, 4px);

// Necessary to ensure children adhere to height of outer container (without
// this gallery surround is not correctly positioned in the middle of the
// card, but rather the middle of the scrolling gallery container).
max-height: var(--frigate-card-max-height);
min-height: var(--frigate-card-min-height);
height: var(--frigate-card-height);

// Ensure all clicks at the top level work.
pointer-events: all;
Expand All @@ -30,8 +26,7 @@
--frigate-card-expand-height: none;
--frigate-card-expand-aspect-ratio: unset;

--frigate-card-max-height: none;
--frigate-card-min-height: none;
--frigate-card-height: auto;
}

:host([dark]) {
Expand Down
9 changes: 5 additions & 4 deletions src/scss/gallery.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
}

frigate-card-surround-basic {
// This must be re-specified (in addition to on the top card element) to
// ensure the filter 'tab' on the gallery drawer is correctly included on the
// non-scrolling part of the gallery.
max-height: var(--frigate-card-max-height);
// The gallery will grow indefinitely in the `unconstrained` aspect ratio
// modes, the surround height needs to be limited to something reasonable in
// order for the media filter to still display somewhere the user can
// easily/continually access.
max-height: 100dvh;
}
6 changes: 2 additions & 4 deletions tests/card-controller/style-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,15 @@ describe('StyleManager', () => {
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(
createConfig({
dimensions: {
max_height: '800px',
min_height: '400px',
height: '800px',
},
}),
);
const manager = new StyleManager(api);

manager.setMinMaxHeight();

expect(element.style.getPropertyValue('--frigate-card-min-height')).toBe('400px');
expect(element.style.getPropertyValue('--frigate-card-max-height')).toBe('800px');
expect(element.style.getPropertyValue('--frigate-card-height')).toBe('800px');
});
});

Expand Down
39 changes: 37 additions & 2 deletions tests/config/management.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
import { PTZControlAction } from '../../src/config/ptz';
import {
Actions,
PerformActionActionConfig,
RawFrigateCardConfig,
frigateCardConfigSchema,
} from '../../src/config/types';
Expand Down Expand Up @@ -3313,7 +3312,7 @@ describe('should handle version specific upgrades', () => {
});
});

it('call-service -> perform-action', () => {
it('rename call-service -> perform-action', () => {
const config = {
type: 'custom:frigate-card',
cameras: [{ camera_entity: 'camera.office' }],
Expand Down Expand Up @@ -3367,5 +3366,41 @@ describe('should handle version specific upgrades', () => {
});
postUpgradeChecks(config);
});

it('rename dimensions.max_height -> dimensions.height', () => {
const config = {
type: 'custom:frigate-card',
cameras: [{ camera_entity: 'camera.office' }],
dimensions: {
max_height: '500px',
},
};
expect(upgradeConfig(config)).toBeTruthy();
expect(config).toEqual({
type: 'custom:frigate-card',
cameras: [{ camera_entity: 'camera.office' }],
dimensions: {
height: '500px',
},
});
postUpgradeChecks(config);
});

it('delete dimensions.min_height', () => {
const config = {
type: 'custom:frigate-card',
cameras: [{ camera_entity: 'camera.office' }],
dimensions: {
min_height: '100px',
},
};
expect(upgradeConfig(config)).toBeTruthy();
expect(config).toEqual({
type: 'custom:frigate-card',
cameras: [{ camera_entity: 'camera.office' }],
dimensions: {},
});
postUpgradeChecks(config);
});
});
});

0 comments on commit d3b9c41

Please sign in to comment.