Description
Issue Description
This issue intends to create a form field to help users to choose colors with a good contrast between them.
The FieldContrastColorPicker component provides two color pickers that allow users to select two colors. It calculates the contrast ratio between these colors according to WCAG guidelines and displays flags indicating whether the current contrast meets each WCAG category. Additionally, the component offers a live preview section where the first color is used as the background and the second as the text color.
How to reproduce / Current behavior
- After pulling this commit, you need to run
npm run build
ornpm run dev
in order to get this component built and ready for use. - You can set, as an example, the following field as a theme option for the default theme like this:
$this->addOption('colorScheme', 'FieldContrastColorPicker', [
'label' => __('plugins.themes.default.option.colorScheme.label'),
'description' => __('plugins.themes.default.option.colorScheme.description'),
]);
- With this the theme is already working, but you can also create a hook to manage the colors:
// ... init() function
Hook::add('TemplateManager::display', [$this, 'schemeColors']);
// ...
public function schemeColors($hookName, $args)
{
$templateMgr = $args[0];
$objColorScheme = json_decode($this->getOption('colorScheme'));
$templateMgr->assign([
'color1' => $objColorScheme->color1,
'color2' => $objColorScheme->color2,
]);
}
- After setting up, you can use the
$color1
and$color2
variables inside the.tpl
files.
What application are you using?
OJS 3.5