Skip to content

Commit

Permalink
Apca UI parameters (#169)
Browse files Browse the repository at this point in the history
* added tests and updated getContrast function for APCA support

* feat: added parameter support (URL) for formula
  • Loading branch information
NateBaldwinDesign authored Aug 9, 2022
1 parent d6ea164 commit c1c8565
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/ui/src/js/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ function paramSetup() {
let baseScale = config.baseScale;
let lightness = (config.lightness) ? config.lightness : config.brightness;
let contrast;
let formula;
if(!config.formula) {
formula = 'wcag2'
} else {
formula = config.formula
}
_theme.formula = formula;

if(!config.contrast) {
contrast = 1;
} else {
Expand Down Expand Up @@ -114,6 +122,10 @@ function paramSetup() {
addRatioInputs(values[0], values[1])
}).then(() => {
setTimeout(() => {
document.getElementById('themeWCAG').value = formula;
let label = document.getElementById('ratioInputLabel')
label.innerHTML = (formula === 'wcag2') ? 'WCAG 2 contrast' : ((formula === 'wcag3') ? 'APCA contrast': 'Contrast');

sortRatios();
}, 500)
});
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ import {sortColorScales} from './js/sortColorScales';
import {
togglePopover
} from './js/popover';
import { forceSimulation } from 'd3';

const { readFileSync } = require('fs')
const posthtml = require('posthtml')
Expand Down Expand Up @@ -166,7 +167,8 @@ function updateParams() {
}),
lightness: _theme.lightness,
contrast: _theme.contrast,
saturation: _theme.saturation
saturation: _theme.saturation,
formula: _theme.formula
};
let url = new URL(window.location);
let params = new URLSearchParams(url.search.slice(1));
Expand Down

0 comments on commit c1c8565

Please sign in to comment.