Skip to content

Commit

Permalink
Refactor(web-twig, demo): Move Tooltip demo scripts to the demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
literat committed Jan 26, 2024
1 parent 0d62024 commit 5038ce1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 40 deletions.
40 changes: 40 additions & 0 deletions apps/web-twig-demo/assets/scripts/tooltip-advanced-usage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Tooltip } from '@lmc-eu/spirit-web/src/js/index.esm';

const checkboxFlip = document.getElementById('my-advanced-flip') as HTMLInputElement;
const checkboxFlipCrossAxis = document.getElementById('my-advanced-flip-cross-axis') as HTMLInputElement;
const checkboxShift = document.getElementById('my-advanced-shift') as HTMLInputElement;
const checkboxSize = document.getElementById('my-advanced-size') as HTMLInputElement;
const select = document.getElementById('my-advanced-select') as HTMLSelectElement;
const selectFallback = document.getElementById('my-advanced-select-fallback') as HTMLSelectElement;

const tooltip = Tooltip.getOrCreateInstance(document.getElementById('my-advanced-tooltip'));

tooltip.show();

checkboxFlip.addEventListener('change', () => tooltip.updateConfig({ enableFlipping: checkboxFlip.checked }));

checkboxFlipCrossAxis.addEventListener('change', () => {
tooltip.updateConfig({ enableFlippingCrossAxis: checkboxFlipCrossAxis.checked });
});

checkboxShift.addEventListener('change', () => {
tooltip.updateConfig({ enableShifting: checkboxShift.checked });
});

checkboxSize.addEventListener('change', () => {
tooltip.updateConfig({ enableSizing: checkboxSize.checked });
});

select.addEventListener('change', () => {
tooltip.updateConfig({ placement: select.value });
});

selectFallback.addEventListener('change', () => {
tooltip.updateConfig({ flipFallbackPlacements: selectFallback.value });
});

const viewport = document.getElementById('my-advanced-viewport');
const content = document.getElementById('my-advanced-content');

viewport.scrollLeft = (content.offsetWidth - viewport.offsetWidth) / 2;
viewport.scrollTop = (content.offsetHeight - viewport.offsetHeight) / 2;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Tooltip from '@lmc-eu/spirit-web/src/js/Tooltip';
import { Tooltip } from '@lmc-eu/spirit-web/src/js/index.esm';

const myTooltipEl = document.getElementById('my-dismissible-tooltip2');
const myTooltip = new Tooltip(myTooltipEl);
Expand Down
1 change: 1 addition & 0 deletions apps/web-twig-demo/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Encore
.addEntry('fileUploaderMetaData', './assets/scripts/file-uploader-meta-data.ts')
.addEntry('formValidations', './assets/scripts/form-validations.ts')
.addEntry('tooltipDismissibleViaJS', './assets/scripts/tooltip-dismissible-via-js.ts')
.addEntry('tooltipAdvancedUsage', './assets/scripts/tooltip-advanced-usage.ts')

// enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
// .enableStimulusBridge('./assets/controllers.json')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,42 +76,4 @@
</div>
</div>

<script type="module">
const checkboxFlip = document.getElementById('my-advanced-flip');
const checkboxFlipCrossAxis = document.getElementById('my-advanced-flipCrossAxis');
const checkboxShift = document.getElementById('my-advanced-shift');
const checkboxSize = document.getElementById('my-advanced-size');
const select = document.getElementById('my-advanced-select');
const selectFallback = document.getElementById('my-advanced-select-fallback');
const tooltip = Tooltip.getOrCreateInstance(document.getElementById('my-advanced-tooltip'));
tooltip.show();
checkboxFlip.addEventListener('change', () => tooltip.updateConfig({enableFlipping: checkboxFlip.checked}));
checkboxFlipCrossAxis.addEventListener('change', () => {
tooltip.updateConfig({enableFlippingCrossAxis: checkboxFlipCrossAxis.checked});
});
checkboxShift.addEventListener('change', () => {
tooltip.updateConfig({enableShifting: checkboxShift.checked});
});
checkboxSize.addEventListener('change', () => {
tooltip.updateConfig({enableSizing: checkboxSize.checked});
});
select.addEventListener('change', () => {
tooltip.updateConfig({placement: select.value});
});
selectFallback.addEventListener('change', () => {
tooltip.updateConfig({flipFallbackPlacements: selectFallback.value});
});
// const viewport = document.getElementById('my-advanced-viewport');
// const content = document.getElementById('my-advanced-content');
// viewport.scrollLeft = (content.offsetWidth - viewport.offsetWidth) / 2;
// viewport.scrollTop = (content.offsetHeight - viewport.offsetHeight) / 2;
</script>
{{ encore_entry_script_tags('tooltipAdvancedUsage') }}

0 comments on commit 5038ce1

Please sign in to comment.