@i-dot-ai-npm/component-library-frontend 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/i-ai-design-system.min.css +1 -1
- package/dist/i-ai-design-system.min.js +1 -1
- package/package.json +1 -1
- package/src/components/modal/_index.scss +87 -0
- package/src/components/modal/index.js +92 -0
- package/src/index.d.ts +9 -0
- package/src/index.js +5 -1
- package/src/index.scss +1 -0
- /package/src/components/{_app-masthead.scss → app-masthead/_index.scss} +0 -0
- /package/src/components/{_button.scss → button/_index.scss} +0 -0
- /package/src/components/{_card.scss → card/_index.scss} +0 -0
- /package/src/components/{_checkboxes.scss → checkboxes/_index.scss} +0 -0
- /package/src/components/{_contents-panel.scss → contents-panel/_index.scss} +0 -0
- /package/src/components/{_form-group.scss → form-group/_index.scss} +0 -0
- /package/src/components/{_header.scss → header/_index.scss} +0 -0
- /package/src/components/{_input.scss → input/_index.scss} +0 -0
- /package/src/components/{_link.scss → link/_index.scss} +0 -0
- /package/src/components/{_select.scss → select/_index.scss} +0 -0
- /package/src/components/{_service-navigation.scss → service-navigation/_index.scss} +0 -0
- /package/src/components/{_table.scss → table/_index.scss} +0 -0
- /package/src/components/{_textarea.scss → textarea/_index.scss} +0 -0
- /package/src/components/{_toggle.scss → toggle/_index.scss} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
.app-masthead{background-color:var(--govuk-brand-colour, #1d70b8)}.app-masthead__title,.app-masthead__body{color:var(--govuk-inverse-text-colour, #ffffff)}.govuk-button.govuk-button--tertiary{background-color:#fff;border:1px solid var(--govuk-border-colour, #cecece);border-bottom:3px solid rgba(0,0,0,0);box-shadow:0 2px 0 #858686;color:var(--govuk-link-colour, #1a65a6)}.govuk-button.govuk-button--tertiary:hover{background-color:#f4f8fb;color:var(--govuk-link-colour, #1a65a6)}.govuk-button.govuk-button--small{padding:6px 8px 4px;font-size:.875rem;line-height:1.25rem;box-shadow:0 1px 0 #858686}.govuk-button-group:has(.govuk-button--small){margin-bottom:0;align-items:center}.govuk-button-group .govuk-button--small{margin-bottom:0;margin-right:2px}.govuk-table--summary .govuk-button-group{flex-wrap:nowrap}.govuk-link--warning{color:var(--govuk-error-colour, #ca3535) !important}.govuk-link:focus{color:var(--govuk-link-colour, #1a65a6);outline:3px solid rgba(0,0,0,0);background-color:rgba(0,0,0,0);box-shadow:none;text-decoration:none}.govuk-link:focus-visible{outline:3px solid rgba(0,0,0,0);background-color:var(--govuk-focus-colour, #ffdd00);box-shadow:0 -2px var(--govuk-focus-colour, #ffdd00),0 4px var(--govuk-focus-text-colour, #0b0c0c);text-decoration:none}.govuk-table--summary .govuk-table__cell--stretch .govuk-link{display:inline-block;width:100%}.govuk-select--subtle{border:1px solid #858686;min-width:0}.govuk-input--subtle{border:1px solid #858686}.govuk-textarea--subtle{border:1px solid #858686}.govuk-checkboxes--subtle .govuk-checkboxes__label::before{border:1px solid #858686;background-color:#fff}.govuk-table--summary .govuk-checkboxes__label{padding:0}.govuk-table--subtle .govuk-table__header{font-size:1rem;line-height:1.25}@media print{.govuk-table--subtle .govuk-table__header{font-size:14pt;line-height:1.2}}.govuk-table--subtle .govuk-table__header{color:#484949}.govuk-table__cell--stretch{width:100%}.govuk-table__cell--no-wrap{white-space:nowrap}.govuk-table__cell--small{font-size:.875rem}.govuk-table--summary .govuk-table__cell{vertical-align:middle}.govuk-form-group--inline{display:flex;flex-direction:row;align-items:center;gap:1rem}.govuk-generic-header{--govuk-text-colour: #0b0c0c;background-color:var(--govuk-surface-background-colour, #f4f8fb)}.govuk-generic-header__homepage-link svg{display:inline-block;width:48px;height:48px;margin-top:-15px;margin-right:10px}.iai-toggle__item{display:flex;align-items:center;gap:8px;margin-bottom:10px}.iai-toggle__item:last-child{margin-bottom:0}.iai-toggle__input{box-sizing:content-box;position:relative;flex:0 0 auto;width:46px;height:24px;margin:0;appearance:none;-webkit-appearance:none;background:none;cursor:pointer}.iai-toggle__input::before{content:"";box-sizing:border-box;position:absolute;top:0;left:0;width:46px;height:24px;border-radius:100px;background-color:#484949;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='14' viewBox='0 0 18 14' fill='none'%3E%3Cpath d='M6.08471 10.6237L2.29164 6.83059L1 8.11313L6.08471 13.1978L17 2.28255L15.7175 1L6.08471 10.6237Z' fill='white' stroke='white'/%3E%3C/svg%3E"),url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 13 13' fill='none'%3E%3Cpath d='M11.167 0L6.5 4.667L1.833 0L0 1.833L4.667 6.5L0 11.167L1.833 13L6.5 8.333L11.167 13L13 11.167L8.333 6.5L13 1.833L11.167 0Z' fill='white'/%3E%3C/svg%3E");background-repeat:no-repeat,no-repeat;background-position:8px center,30px center;background-size:12px 12px,10px 10px;transition:150ms}.iai-toggle__input::after{content:"";box-sizing:border-box;position:absolute;top:50%;left:1px;width:22px;height:22px;border:1px solid rgba(0,0,0,.25);border-radius:50%;background-color:#fff;transform:translateY(-50%);transition:150ms}.iai-toggle__input:checked::before{background-color:var(--govuk-success-colour, #0f7a52)}.iai-toggle__input:checked::after{left:23px}.iai-toggle__input:focus-visible::before{outline:3px solid rgba(0,0,0,0);outline-offset:0;box-shadow:0 0 0 4px var(--govuk-focus-colour, #ffdd00)}.iai-toggle__label{align-self:center;margin-bottom:0;padding:7px 0;cursor:pointer;touch-action:manipulation}.iai-toggle__input:disabled{cursor:not-allowed}.iai-toggle__input:disabled::before{background-color:#cecece}.iai-toggle__item:has(.iai-toggle__input:disabled) .iai-toggle__label{opacity:.5;cursor:not-allowed}@media(prefers-reduced-motion: reduce){.iai-toggle__input::before,.iai-toggle__input::after{transition-duration:0ms}}.iai-card-group{display:flex;flex-direction:column;gap:20px;margin-bottom:20px}@media(min-width: 768px){.iai-card-group{display:grid;grid-template-columns:repeat(3, 1fr)}}.iai-card-group__item{height:100%}.iai-card{position:relative;height:100%;box-sizing:border-box;padding:20px;background-color:#fff;border:2px solid #cecece}.iai-card__icon{margin-bottom:15px;color:#484949}.iai-card__icon svg{display:block}.iai-card:hover .iai-card__icon{color:#fff}.iai-card:hover{background-color:#0b0c0c}.iai-card__heading{margin:0 0 5px;font-size:1.1875rem;line-height:1.3157894737}.iai-card__link{color:var(--govuk-link-colour, #1a65a6);text-decoration:underline}.iai-card__link:after{content:"";position:absolute;inset:0}.iai-card__content{margin:0;color:var(--govuk-text-colour, #0b0c0c)}.iai-card:hover .iai-card__link,.iai-card:hover .iai-card__content{color:#fff !important}.iai-card--secondary{padding:15px 20px;background-color:#f3f3f3;border:none}.contents-panel{padding-right:15px;font-family:"GDS Transport",arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}
|
|
1
|
+
.app-masthead{background-color:var(--govuk-brand-colour, #1d70b8)}.app-masthead__title,.app-masthead__body{color:var(--govuk-inverse-text-colour, #ffffff)}.govuk-button.govuk-button--tertiary{background-color:#fff;border:1px solid var(--govuk-border-colour, #cecece);border-bottom:3px solid rgba(0,0,0,0);box-shadow:0 2px 0 #858686;color:var(--govuk-link-colour, #1a65a6)}.govuk-button.govuk-button--tertiary:hover{background-color:#f4f8fb;color:var(--govuk-link-colour, #1a65a6)}.govuk-button.govuk-button--small{padding:6px 8px 4px;font-size:.875rem;line-height:1.25rem;box-shadow:0 1px 0 #858686}.govuk-button-group:has(.govuk-button--small){margin-bottom:0;align-items:center}.govuk-button-group .govuk-button--small{margin-bottom:0;margin-right:2px}.govuk-table--summary .govuk-button-group{flex-wrap:nowrap}.govuk-link--warning{color:var(--govuk-error-colour, #ca3535) !important}.govuk-link:focus{color:var(--govuk-link-colour, #1a65a6);outline:3px solid rgba(0,0,0,0);background-color:rgba(0,0,0,0);box-shadow:none;text-decoration:none}.govuk-link:focus-visible{outline:3px solid rgba(0,0,0,0);background-color:var(--govuk-focus-colour, #ffdd00);box-shadow:0 -2px var(--govuk-focus-colour, #ffdd00),0 4px var(--govuk-focus-text-colour, #0b0c0c);text-decoration:none}.govuk-table--summary .govuk-table__cell--stretch .govuk-link{display:inline-block;width:100%}.govuk-select--subtle{border:1px solid #858686;min-width:0}.govuk-input--subtle{border:1px solid #858686}.govuk-textarea--subtle{border:1px solid #858686}.govuk-checkboxes--subtle .govuk-checkboxes__label::before{border:1px solid #858686;background-color:#fff}.govuk-table--summary .govuk-checkboxes__label{padding:0}.govuk-table--subtle .govuk-table__header{font-size:1rem;line-height:1.25}@media print{.govuk-table--subtle .govuk-table__header{font-size:14pt;line-height:1.2}}.govuk-table--subtle .govuk-table__header{color:#484949}.govuk-table__cell--stretch{width:100%}.govuk-table__cell--no-wrap{white-space:nowrap}.govuk-table__cell--small{font-size:.875rem}.govuk-table--summary .govuk-table__cell{vertical-align:middle}.govuk-form-group--inline{display:flex;flex-direction:row;align-items:center;gap:1rem}.govuk-generic-header{--govuk-text-colour: #0b0c0c;background-color:var(--govuk-surface-background-colour, #f4f8fb)}.govuk-generic-header__homepage-link svg{display:inline-block;width:48px;height:48px;margin-top:-15px;margin-right:10px}.iai-toggle__item{display:flex;align-items:center;gap:8px;margin-bottom:10px}.iai-toggle__item:last-child{margin-bottom:0}.iai-toggle__input{box-sizing:content-box;position:relative;flex:0 0 auto;width:46px;height:24px;margin:0;appearance:none;-webkit-appearance:none;background:none;cursor:pointer}.iai-toggle__input::before{content:"";box-sizing:border-box;position:absolute;top:0;left:0;width:46px;height:24px;border-radius:100px;background-color:#484949;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='14' viewBox='0 0 18 14' fill='none'%3E%3Cpath d='M6.08471 10.6237L2.29164 6.83059L1 8.11313L6.08471 13.1978L17 2.28255L15.7175 1L6.08471 10.6237Z' fill='white' stroke='white'/%3E%3C/svg%3E"),url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 13 13' fill='none'%3E%3Cpath d='M11.167 0L6.5 4.667L1.833 0L0 1.833L4.667 6.5L0 11.167L1.833 13L6.5 8.333L11.167 13L13 11.167L8.333 6.5L13 1.833L11.167 0Z' fill='white'/%3E%3C/svg%3E");background-repeat:no-repeat,no-repeat;background-position:8px center,30px center;background-size:12px 12px,10px 10px;transition:150ms}.iai-toggle__input::after{content:"";box-sizing:border-box;position:absolute;top:50%;left:1px;width:22px;height:22px;border:1px solid rgba(0,0,0,.25);border-radius:50%;background-color:#fff;transform:translateY(-50%);transition:150ms}.iai-toggle__input:checked::before{background-color:var(--govuk-success-colour, #0f7a52)}.iai-toggle__input:checked::after{left:23px}.iai-toggle__input:focus-visible::before{outline:3px solid rgba(0,0,0,0);outline-offset:0;box-shadow:0 0 0 4px var(--govuk-focus-colour, #ffdd00)}.iai-toggle__label{align-self:center;margin-bottom:0;padding:7px 0;cursor:pointer;touch-action:manipulation}.iai-toggle__input:disabled{cursor:not-allowed}.iai-toggle__input:disabled::before{background-color:#cecece}.iai-toggle__item:has(.iai-toggle__input:disabled) .iai-toggle__label{opacity:.5;cursor:not-allowed}@media(prefers-reduced-motion: reduce){.iai-toggle__input::before,.iai-toggle__input::after{transition-duration:0ms}}.iai-modal{width:100%;max-width:640px;padding:0;border:4px solid var(--govuk-text-colour, #0b0c0c);background-color:#fff;color:var(--govuk-text-colour, #0b0c0c)}.iai-modal:not([open]){display:none}.iai-modal::backdrop{background-color:rgba(11,12,12,.6)}.iai-modal:focus-visible{outline:3px solid var(--govuk-focus-colour, #ffdd00);outline-offset:0}.iai-modal__container{padding:20px}@media(min-width: 40.0625em){.iai-modal__container{padding:30px}}.iai-modal__container{display:flex;flex-direction:column;gap:20px}.iai-modal__title{margin:0}.iai-modal__body{font-family:"GDS Transport",arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}/*! Copyright (c) 2011 by Margaret Calvert & Henrik Kubel. All rights reserved. The font has been customised for exclusive use on gov.uk. This cut is not commercially available. */@font-face{font-family:"GDS Transport";font-style:normal;font-weight:normal;font-display:fallback;src:url("/assets/fonts/light-94a07e06a1-v2.woff2") format("woff2"),url("/assets/fonts/light-f591b13f7d-v2.woff") format("woff")}@font-face{font-family:"GDS Transport";font-style:normal;font-weight:bold;font-display:fallback;src:url("/assets/fonts/bold-b542beb274-v2.woff2") format("woff2"),url("/assets/fonts/bold-affa96571d-v2.woff") format("woff")}@media print{.iai-modal__body{font-family:sans-serif}}.iai-modal__body{font-weight:400;font-size:1.1875rem;line-height:1.3157894737}@media print{.iai-modal__body{font-size:14pt;line-height:1.15}}.iai-modal__body{margin:0}.iai-modal__body>:last-child{margin-bottom:0}.iai-modal__footer{margin:0}.iai-modal-scroll-locked{overflow:hidden}@media(prefers-reduced-motion: no-preference){.iai-modal[open]{animation:iai-modal-fade-in 150ms ease-out}.iai-modal[open]::backdrop{animation:iai-modal-backdrop-fade-in 150ms ease-out}}@keyframes iai-modal-fade-in{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:translateY(0)}}@keyframes iai-modal-backdrop-fade-in{from{opacity:0}to{opacity:1}}.iai-card-group{display:flex;flex-direction:column;gap:20px;margin-bottom:20px}@media(min-width: 768px){.iai-card-group{display:grid;grid-template-columns:repeat(3, 1fr)}}.iai-card-group__item{height:100%}.iai-card{position:relative;height:100%;box-sizing:border-box;padding:20px;background-color:#fff;border:2px solid #cecece}.iai-card__icon{margin-bottom:15px;color:#484949}.iai-card__icon svg{display:block}.iai-card:hover .iai-card__icon{color:#fff}.iai-card:hover{background-color:#0b0c0c}.iai-card__heading{margin:0 0 5px;font-size:1.1875rem;line-height:1.3157894737}.iai-card__link{color:var(--govuk-link-colour, #1a65a6);text-decoration:underline}.iai-card__link:after{content:"";position:absolute;inset:0}.iai-card__content{margin:0;color:var(--govuk-text-colour, #0b0c0c)}.iai-card:hover .iai-card__link,.iai-card:hover .iai-card__content{color:#fff !important}.iai-card--secondary{padding:15px 20px;background-color:#f3f3f3;border:none}.contents-panel{padding-right:15px;font-family:"GDS Transport",arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}@media print{.contents-panel{font-family:sans-serif}}.contents-panel{font-weight:400;font-size:1rem;line-height:1.25}@media print{.contents-panel{font-size:14pt;line-height:1.2}}.contents-panel__list-heading{font-size:1.1875rem;line-height:1.3157894737}@media print{.contents-panel__list-heading{font-size:14pt;line-height:1.15}}.contents-panel__list-heading{font-weight:400;margin:0;padding:10px 15px 10px 0;color:#484949}.contents-panel__list-heading:first-of-type{padding-top:0}.contents-panel__list{margin:0 0 20px;padding:0;list-style-type:none}.contents-panel__list-item{margin-bottom:5px;padding-top:5px;padding-bottom:5px}.contents-panel__link{padding:2px 0}.contents-panel__list-item--current{margin-left:-14px;padding-left:10px;border-left:4px solid #1d70b8;background-color:#fff}.contents-panel__list-item--current .contents-panel__link[aria-current=page]{font-weight:700}.govuk-template__body--iai-theme .govuk-service-navigation__item{border-color:var(--govuk-brand-colour, #1d70b8)}.govuk-template__body--iai-theme .govuk-service-navigation__link,.govuk-template__body--iai-theme .govuk-service-navigation__link:visited,.govuk-template__body--iai-theme .govuk-service-navigation__link:hover{color:var(--govuk-text-colour, #0b0c0c)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function i(){}export{i as
|
|
1
|
+
var l="iai-modal",c=`data-${l}-init`,s="iai-modal-scroll-locked";function d(){document.documentElement.classList.remove(s)}function a(t){!t||t.open||(t.showModal(),t.focus(),document.documentElement.classList.add(s))}function n(t){!t||!t.open||t.close()}function i(t){!t||t.hasAttribute(c)||(t.setAttribute(c,""),t.addEventListener("click",e=>{if(e.target.closest("[data-iai-modal-close]")){n(t);return}if(e.target!==t)return;let o=t.getBoundingClientRect();(e.clientX<o.left||e.clientX>o.right||e.clientY<o.top||e.clientY>o.bottom)&&n(t)}),t.addEventListener("close",d))}var r=!1;function u(){document.querySelectorAll(`dialog.iai-modal[data-module="${l}"]`).forEach(i),!r&&(r=!0,document.addEventListener("click",t=>{let e=t.target.closest("[data-iai-modal-open]");if(!e)return;let o=document.getElementById(e.getAttribute("data-iai-modal-open"));o&&(i(o),a(o))}))}function L(){u()}export{n as closeModal,L as initAllIAIDesignSystem,i as initModal,a as openModal};
|
package/package.json
CHANGED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
@use "pkg:govuk-frontend/base" as *;
|
|
2
|
+
|
|
3
|
+
$iai-modal-max-width: 640px;
|
|
4
|
+
$iai-modal-border-width: 4px;
|
|
5
|
+
|
|
6
|
+
.iai-modal {
|
|
7
|
+
width: 100%;
|
|
8
|
+
max-width: $iai-modal-max-width;
|
|
9
|
+
padding: 0;
|
|
10
|
+
border: $iai-modal-border-width solid $govuk-text-colour;
|
|
11
|
+
background-color: govuk-colour("white");
|
|
12
|
+
color: $govuk-text-colour;
|
|
13
|
+
|
|
14
|
+
&:not([open]) {
|
|
15
|
+
display: none;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&::backdrop {
|
|
19
|
+
background-color: rgba(govuk-colour("black"), 0.6);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&:focus-visible {
|
|
23
|
+
outline: $govuk-focus-width solid $govuk-focus-colour;
|
|
24
|
+
outline-offset: 0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.iai-modal__container {
|
|
29
|
+
@include govuk-responsive-padding(6);
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-direction: column;
|
|
32
|
+
gap: govuk-spacing(4);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.iai-modal__title {
|
|
36
|
+
margin: 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.iai-modal__body {
|
|
40
|
+
@include govuk-font($size: 19);
|
|
41
|
+
margin: 0;
|
|
42
|
+
|
|
43
|
+
> :last-child {
|
|
44
|
+
margin-bottom: 0;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.iai-modal__footer {
|
|
49
|
+
margin: 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Set on the document by the central JS while a modal is open.
|
|
53
|
+
.iai-modal-scroll-locked {
|
|
54
|
+
overflow: hidden;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
58
|
+
.iai-modal[open] {
|
|
59
|
+
animation: iai-modal-fade-in 150ms ease-out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.iai-modal[open]::backdrop {
|
|
63
|
+
animation: iai-modal-backdrop-fade-in 150ms ease-out;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@keyframes iai-modal-fade-in {
|
|
68
|
+
from {
|
|
69
|
+
opacity: 0;
|
|
70
|
+
transform: translateY(govuk-spacing(2));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
to {
|
|
74
|
+
opacity: 1;
|
|
75
|
+
transform: translateY(0);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@keyframes iai-modal-backdrop-fade-in {
|
|
80
|
+
from {
|
|
81
|
+
opacity: 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
to {
|
|
85
|
+
opacity: 1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// i.AI Design System — Modal behaviour over the native <dialog>.
|
|
2
|
+
//
|
|
3
|
+
// Markup:
|
|
4
|
+
// <dialog class="iai-modal" data-module="iai-modal"> ... </dialog>
|
|
5
|
+
// <button data-iai-modal-open="dialog-id">Open</button>
|
|
6
|
+
// <button data-iai-modal-close>Close</button>
|
|
7
|
+
//
|
|
8
|
+
// Framework wrappers driving the modal from an `open` prop should call the
|
|
9
|
+
// exported open()/close() helpers rather than re-implementing this logic.
|
|
10
|
+
|
|
11
|
+
const MODULE = "iai-modal";
|
|
12
|
+
const INIT_FLAG = `data-${MODULE}-init`;
|
|
13
|
+
const SCROLL_LOCK_CLASS = "iai-modal-scroll-locked";
|
|
14
|
+
|
|
15
|
+
function unlockScroll() {
|
|
16
|
+
document.documentElement.classList.remove(SCROLL_LOCK_CLASS);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Open a modal dialog.
|
|
21
|
+
* @param {HTMLDialogElement} dialog
|
|
22
|
+
*/
|
|
23
|
+
export function open(dialog) {
|
|
24
|
+
if (!dialog || dialog.open) return;
|
|
25
|
+
dialog.showModal();
|
|
26
|
+
dialog.focus();
|
|
27
|
+
document.documentElement.classList.add(SCROLL_LOCK_CLASS);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Close a modal dialog. Scroll-lock release happens in the dialog's `close`
|
|
32
|
+
* event handler (see initModal), which also covers Esc. Native <dialog>
|
|
33
|
+
* restores focus to the opener itself.
|
|
34
|
+
* @param {HTMLDialogElement} dialog
|
|
35
|
+
*/
|
|
36
|
+
export function close(dialog) {
|
|
37
|
+
if (!dialog || !dialog.open) return;
|
|
38
|
+
dialog.close();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Enhance a single dialog element. Idempotent.
|
|
43
|
+
* @param {HTMLDialogElement} dialog
|
|
44
|
+
*/
|
|
45
|
+
export function initModal(dialog) {
|
|
46
|
+
if (!dialog || dialog.hasAttribute(INIT_FLAG)) return;
|
|
47
|
+
dialog.setAttribute(INIT_FLAG, "");
|
|
48
|
+
|
|
49
|
+
dialog.addEventListener("click", (event) => {
|
|
50
|
+
if (event.target.closest("[data-iai-modal-close]")) {
|
|
51
|
+
close(dialog);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// A ::backdrop click reports the dialog as target but lands outside its
|
|
55
|
+
// content rect.
|
|
56
|
+
if (event.target !== dialog) return;
|
|
57
|
+
const rect = dialog.getBoundingClientRect();
|
|
58
|
+
const outside =
|
|
59
|
+
event.clientX < rect.left ||
|
|
60
|
+
event.clientX > rect.right ||
|
|
61
|
+
event.clientY < rect.top ||
|
|
62
|
+
event.clientY > rect.bottom;
|
|
63
|
+
if (outside) close(dialog);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// shortcut: unlocks unconditionally (one modal at a time); revisit if
|
|
67
|
+
// stacked modals are ever supported.
|
|
68
|
+
dialog.addEventListener("close", unlockScroll);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let triggersBound = false;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Wire up every modal and its triggers on the page. Idempotent.
|
|
75
|
+
*/
|
|
76
|
+
export function initAllModals() {
|
|
77
|
+
document
|
|
78
|
+
.querySelectorAll(`dialog.iai-modal[data-module="${MODULE}"]`)
|
|
79
|
+
.forEach(initModal);
|
|
80
|
+
|
|
81
|
+
if (triggersBound) return;
|
|
82
|
+
triggersBound = true;
|
|
83
|
+
document.addEventListener("click", (event) => {
|
|
84
|
+
const trigger = event.target.closest("[data-iai-modal-open]");
|
|
85
|
+
if (!trigger) return;
|
|
86
|
+
const dialog = document.getElementById(trigger.getAttribute("data-iai-modal-open"));
|
|
87
|
+
if (dialog) {
|
|
88
|
+
initModal(dialog);
|
|
89
|
+
open(dialog);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -5,3 +5,12 @@
|
|
|
5
5
|
* `initAll()`.
|
|
6
6
|
*/
|
|
7
7
|
export function initAllIAIDesignSystem(): void;
|
|
8
|
+
|
|
9
|
+
/** Open a modal dialog and lock background scroll. */
|
|
10
|
+
export function openModal(dialog: HTMLDialogElement): void;
|
|
11
|
+
|
|
12
|
+
/** Close a modal dialog and restore focus to the element that opened it. */
|
|
13
|
+
export function closeModal(dialog: HTMLDialogElement): void;
|
|
14
|
+
|
|
15
|
+
/** Enhance a single modal dialog element. Idempotent. */
|
|
16
|
+
export function initModal(dialog: HTMLDialogElement): void;
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
// Progressive enhancement for i.AI components. Call after govuk-frontend's
|
|
4
4
|
// initAll(). Each component's enhancement lives in its own module.
|
|
5
5
|
|
|
6
|
+
import { initAllModals } from "./components/modal/index.js";
|
|
7
|
+
|
|
8
|
+
export { open as openModal, close as closeModal, initModal } from "./components/modal/index.js";
|
|
9
|
+
|
|
6
10
|
export function initAllIAIDesignSystem() {
|
|
7
|
-
|
|
11
|
+
initAllModals();
|
|
8
12
|
}
|
package/src/index.scss
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|