Skip to content

[UI-Library][FieldContrastColorPicker] Create a New Accessible Form Component. #11169

@Godoy0722

Description

@Godoy0722

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

  1. After pulling this commit, you need to run npm run build or npm run dev in order to get this component built and ready for use.
  2. 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'),
        ]);
  1. 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,
        ]);
    }
  1. After setting up, you can use the $color1 and $color2 variables inside the .tpl files.

What application are you using?

OJS 3.5

Metadata

Metadata

Assignees

Labels

AccessibilityAny issue that impacts assistive technology or users with visual or physical impairments.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions