Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color picker call events #136

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions resources/views/components/forms/inputs/color-picker.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@

input.setAttribute('value', currentColor);
$root.setAttribute('title', currentColor);

$dispatch('buk:color-save', {
id: '{{ $id }}',
color: currentColor
});
});

pickr.on('change', function (color) {
let currentColor = color ? color.toHEXA().toString() : '';

$dispatch('buk:color-change', {
id: '{{ $id }}',
color: currentColor
});
});
"
{{ $attributes->merge(['title' => $value]) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@

input.setAttribute('value', currentColor);
$root.setAttribute('title', currentColor);

$dispatch('buk:color-save', {
id: 'mainColor',
color: currentColor
});
});

pickr.on('change', function (color) {
let currentColor = color ? color.toHEXA().toString() : '';

$dispatch('buk:color-change', {
id: 'mainColor',
color: currentColor
});
});
"
title="" class="mr-2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@

input.setAttribute('value', currentColor);
$root.setAttribute('title', currentColor);

$dispatch('buk:color-save', {
id: 'color',
color: currentColor
});
});

pickr.on('change', function (color) {
let currentColor = color ? color.toHEXA().toString() : '';

$dispatch('buk:color-change', {
id: 'color',
color: currentColor
});
});
"
title="#FF9900"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@

input.setAttribute('value', currentColor);
$root.setAttribute('title', currentColor);

$dispatch('buk:color-save', {
id: 'color',
color: currentColor
});
});

pickr.on('change', function (color) {
let currentColor = color ? color.toHEXA().toString() : '';

$dispatch('buk:color-change', {
id: 'color',
color: currentColor
});
});
"
title=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@

input.setAttribute('value', currentColor);
$root.setAttribute('title', currentColor);

$dispatch('buk:color-save', {
id: 'color',
color: currentColor
});
});

pickr.on('change', function (color) {
let currentColor = color ? color.toHEXA().toString() : '';

$dispatch('buk:color-change', {
id: 'color',
color: currentColor
});
});
"
title=""
Expand Down
11 changes: 9 additions & 2 deletions tests/Browser/Forms/Inputs/ColorPickerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function it_can_render_color_picker_and_choose_color() {
new ComponentConfig('color-picker', [
'name' => 'color1',
'dusk' => 'color1',
'x-on:buk:color-save' => 'window.test_render = `1 ${$event.detail.color}`',
])
)
)
Expand All @@ -30,7 +31,8 @@ public function it_can_render_color_picker_and_choose_color() {
->waitFor('.pcr-palette')
->click('.pcr-palette')
->click('.pcr-save')
->waitUntil("$inputElement.value !== ''");
->waitUntil("$inputElement.value !== ''")
->assertScript('return window.test_render === `1 ${' . $inputElement . '.value}`');
});
}

Expand All @@ -45,10 +47,12 @@ public function it_can_render_multiple_color_pickers_and_choose_color() {
new ComponentConfig('color-picker', [
'name' => 'color1',
'dusk' => 'color1',
'@buk:color-change' => 'window.test_render_multiple1 = `1 ${$event.detail.color}`',
]),
new ComponentConfig('color-picker', [
'name' => 'color2',
'dusk' => 'color2',
'@buk:color-change' => 'window.test_render_multiple2 = `2 ${$event.detail.color}`',
]),
])
)
Expand All @@ -59,12 +63,15 @@ public function it_can_render_multiple_color_pickers_and_choose_color() {
->click('.pcr-app .pcr-save')
->waitUntil("$inputElement1.value !== ''")
->click('@color1 button')
->assertScript('return window.test_render_multiple1 === `1 ${' . $inputElement1 . '.value}`')
->assertScript('return window.test_render_multiple2 === undefined')
->assertScript("return $inputElement2.value === ''")
->click('@color2 button')
->waitFor('.pcr-app:last-child .pcr-palette')
->click('.pcr-app:last-child .pcr-palette')
->click('.pcr-app:last-child .pcr-save')
->waitUntil("$inputElement2.value !== ''");
->waitUntil("$inputElement2.value !== ''")
->assertScript('return window.test_render_multiple2 === `2 ${' . $inputElement2 . '.value}`');
});
}
}
Loading