Skip to content

Commit

Permalink
fix(gv-plans): improve a11y
Browse files Browse the repository at this point in the history
  • Loading branch information
gcusnieux committed Feb 8, 2024
1 parent a9a76c2 commit 33f151a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
11 changes: 0 additions & 11 deletions src/lib/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,3 @@ export const getCssVar = function getCssVar(element, variableName, defaultValue
}
return defaultValue;
};

export function hexToRGB(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex.trim());
return result
? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16),
}
: null;
}
18 changes: 8 additions & 10 deletions src/molecules/gv-plans/gv-plans.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
import { classMap } from 'lit/directives/class-map.js';
import { css, LitElement, html } from 'lit';
import { dispatchCustomEvent } from '../../lib/events';
import { getCssVar, hexToRGB } from '../../lib/style';

import { i18n } from '../../lib/i18n';
import { link } from '../../styles/link';
import { repeat } from 'lit/directives/repeat.js';
import { skeleton } from '../../styles/skeleton';
import { empty } from '../../styles/empty';
import { styleMap } from 'lit/directives/style-map.js';
import '../../atoms/gv-icon';

/**
Expand Down Expand Up @@ -83,6 +81,7 @@ export class GvPlans extends LitElement {
.plans {
display: flex;
list-style-type: none;
border: 1px solid var(--bgc);
border-radius: 2px;
padding: 0;
margin: 0;
Expand All @@ -94,12 +93,18 @@ export class GvPlans extends LitElement {
padding: 16px;
line-height: 24px;
cursor: pointer;
opacity: 0.5;
}
.plan:hover {
opacity: 1;
}
.plan.active {
background-color: var(--bgc);
color: var(--fc);
transition: all 0.2s ease-in;
opacity: 1;
}
.name {
Expand Down Expand Up @@ -373,13 +378,6 @@ export class GvPlans extends LitElement {
}

render() {
const bgc = getCssVar(this, '--gv-plans--bgc', '#5A7684');
const { r, g, b } = hexToRGB(bgc);
const style = {
backgroundColor: `rgba(${r}, ${g}, ${b}, 0.1)`,
color: `rgba(${r}, ${g}, ${b}, 0.5)`,
};

if (!this.skeleton) {
if (this._error) {
return html`<div class="error">
Expand All @@ -396,7 +394,7 @@ export class GvPlans extends LitElement {
const classes = { skeleton: this.skeleton };
const currentPlans = this.plans;
return html`<div class="${classMap(classes)}">
<ul class="plans" style="${styleMap(style)}">
<ul class="plans">
${this._renderHeader(currentPlans)}
</ul>
<div class="selectors">${this._renderTriangles(currentPlans)}</div>
Expand Down

0 comments on commit 33f151a

Please sign in to comment.