@pega/cosmos-react-core 10.0.0-build.12.5 → 10.0.0-build.12.6
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/lib/components/Actions/Actions.d.ts.map +1 -1
- package/lib/components/Actions/Actions.js +13 -13
- package/lib/components/Actions/Actions.js.map +1 -1
- package/lib/components/AppShell/AppShell.js +1 -1
- package/lib/components/AppShell/AppShell.js.map +1 -1
- package/lib/components/Lightbox/Lightbox.d.ts.map +1 -1
- package/lib/components/Lightbox/Lightbox.js +25 -9
- package/lib/components/Lightbox/Lightbox.js.map +1 -1
- package/lib/components/Lightbox/Lightbox.styles.d.ts +1 -0
- package/lib/components/Lightbox/Lightbox.styles.d.ts.map +1 -1
- package/lib/components/Lightbox/Lightbox.styles.js +40 -31
- package/lib/components/Lightbox/Lightbox.styles.js.map +1 -1
- package/lib/components/Lightbox/ZoomControls/ZoomControls.d.ts +14 -0
- package/lib/components/Lightbox/ZoomControls/ZoomControls.d.ts.map +1 -0
- package/lib/components/Lightbox/ZoomControls/ZoomControls.js +23 -0
- package/lib/components/Lightbox/ZoomControls/ZoomControls.js.map +1 -0
- package/lib/components/Lightbox/ZoomControls/ZoomControls.styles.d.ts +5 -0
- package/lib/components/Lightbox/ZoomControls/ZoomControls.styles.d.ts.map +1 -0
- package/lib/components/Lightbox/ZoomControls/ZoomControls.styles.js +40 -0
- package/lib/components/Lightbox/ZoomControls/ZoomControls.styles.js.map +1 -0
- package/lib/components/Lightbox/ZoomControls/ZoomControls.test-ids.d.ts +2 -0
- package/lib/components/Lightbox/ZoomControls/ZoomControls.test-ids.d.ts.map +1 -0
- package/lib/components/Lightbox/ZoomControls/ZoomControls.test-ids.js +7 -0
- package/lib/components/Lightbox/ZoomControls/ZoomControls.test-ids.js.map +1 -0
- package/lib/components/Lightbox/ZoomControls/index.d.ts +4 -0
- package/lib/components/Lightbox/ZoomControls/index.d.ts.map +1 -0
- package/lib/components/Lightbox/ZoomControls/index.js +3 -0
- package/lib/components/Lightbox/ZoomControls/index.js.map +1 -0
- package/lib/components/Lightbox/useZoom.d.ts +30 -0
- package/lib/components/Lightbox/useZoom.d.ts.map +1 -0
- package/lib/components/Lightbox/useZoom.js +183 -0
- package/lib/components/Lightbox/useZoom.js.map +1 -0
- package/lib/components/MultiStepForm/MultiStepForm.d.ts.map +1 -1
- package/lib/components/MultiStepForm/MultiStepForm.js +0 -7
- package/lib/components/MultiStepForm/MultiStepForm.js.map +1 -1
- package/lib/hooks/useI18n.d.ts +5 -0
- package/lib/hooks/useI18n.d.ts.map +1 -1
- package/lib/i18n/default.d.ts +5 -0
- package/lib/i18n/default.d.ts.map +1 -1
- package/lib/i18n/default.js +6 -1
- package/lib/i18n/default.js.map +1 -1
- package/lib/i18n/i18n.d.ts +5 -0
- package/lib/i18n/i18n.d.ts.map +1 -1
- package/lib/utils/clamp.d.ts +11 -0
- package/lib/utils/clamp.d.ts.map +1 -0
- package/lib/utils/clamp.js +13 -0
- package/lib/utils/clamp.js.map +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +1 -0
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -138,46 +138,55 @@ export const StyledContainer = styled.div(({ theme }) => {
|
|
|
138
138
|
`;
|
|
139
139
|
});
|
|
140
140
|
StyledContainer.defaultProps = defaultThemeProp;
|
|
141
|
-
export const StyledMediaContainer = styled.div(({ theme, global }) => {
|
|
141
|
+
export const StyledMediaContainer = styled.div(({ theme, global, zoomable }) => {
|
|
142
142
|
return css `
|
|
143
|
-
|
|
143
|
+
position: relative;
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
${!global &&
|
|
146
146
|
css `
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
background-color: ${theme.base.colors.gray['extra-dark']};
|
|
148
|
+
overflow-y: auto;
|
|
149
|
+
`}
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
& > div {
|
|
152
|
+
position: absolute;
|
|
153
|
+
inset: 0;
|
|
154
|
+
}
|
|
155
155
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
${zoomable &&
|
|
157
|
+
css `
|
|
158
|
+
overflow: auto;
|
|
159
|
+
|
|
160
|
+
&:focus-visible {
|
|
161
|
+
box-shadow: ${theme.base.shadow['focus-inset']};
|
|
162
|
+
}
|
|
163
|
+
`}
|
|
164
|
+
|
|
165
|
+
${StyledErrorState} {
|
|
166
|
+
margin: auto;
|
|
167
|
+
& > ${StyledText} {
|
|
168
|
+
color: ${theme.base.palette.light};
|
|
169
|
+
}
|
|
160
170
|
}
|
|
161
|
-
}
|
|
162
171
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
172
|
+
img,
|
|
173
|
+
video,
|
|
174
|
+
audio {
|
|
175
|
+
display: block;
|
|
176
|
+
max-width: calc(100% - 5rem);
|
|
177
|
+
max-height: 100%;
|
|
178
|
+
margin: auto;
|
|
179
|
+
}
|
|
171
180
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
181
|
+
img,
|
|
182
|
+
video {
|
|
183
|
+
${!global &&
|
|
175
184
|
css `
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
185
|
+
margin-block-start: calc(${theme.base.spacing} * 4);
|
|
186
|
+
max-width: calc(100% - calc(${theme.base.spacing} * 4));
|
|
187
|
+
`}
|
|
188
|
+
}
|
|
189
|
+
`;
|
|
181
190
|
});
|
|
182
191
|
export const StyledObject = styled.object `
|
|
183
192
|
display: block;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lightbox.styles.js","sourceRoot":"","sources":["../../../src/components/Lightbox/Lightbox.styles.ts"],"names":[],"mapp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isually, rgba } from 'polished';\n\nimport { defaultThemeProp } from '../../theme';\nimport { tryCatch } from '../../utils';\nimport { calculateFontSize } from '../../styles';\nimport BareButton from '../Button/BareButton';\nimport { StyledIcon } from '../Icon';\nimport { StyledMetaList } from '../MetaList/MetaList';\nimport { StyledErrorState } from '../ErrorState';\nimport Text, { StyledText } from '../Text';\nimport { useDirection } from '../../hooks';\nimport Backdrop from '../Backdrop';\nimport { StyledLink } from '../Link/Link';\nimport { ellipsisOverflow } from '../../styles/mixins';\n\nexport const StyledHeader = styled.header<{ global: boolean }>(({ theme, global }) => {\n const color: string | undefined = tryCatch(() =>\n rgba(theme.base.palette.light, theme.base.transparency['transparent-2'])\n );\n\n return css`\n position: relative;\n width: 100%;\n padding: ${theme.base.spacing};\n color: ${color};\n ${!global &&\n css`\n background-color: ${theme.base.colors.gray['extra-dark']};\n border-block-end: 0.0625rem solid ${theme.base.palette['border-line']};\n `}\n\n ${StyledMetaList} {\n justify-content: center;\n li {\n color: ${color};\n }\n }\n `;\n});\n\nStyledHeader.defaultProps = defaultThemeProp;\n\nexport const StyledCountTracker = styled.div(({ theme }) => {\n const fontSize = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n\n return css`\n font-size: ${fontSize.xs};\n text-align: center;\n min-width: calc(2 * ${theme.base['hit-area']['mouse-min']});\n\n @media (pointer: coarse) {\n min-width: calc(2 * ${theme.base['hit-area']['finger-min']});\n }\n `;\n});\n\nStyledCountTracker.defaultProps = defaultThemeProp;\n\nexport const StyledInfo = styled.div(({ theme }) => {\n return css`\n color: ${theme.base.palette.light};\n font-weight: ${theme.base['font-weight']['semi-bold']};\n min-width: 0;\n\n ${StyledLink} {\n color: inherit;\n text-decoration: underline;\n }\n `;\n});\n\nStyledInfo.defaultProps = defaultThemeProp;\n\nexport const StyledNavButton = styled(BareButton)(({ theme }) => {\n const bg = tryCatch(() => rgba(theme.base.colors.gray.medium, 0.5));\n const hoverBg = tryCatch(() => rgba(theme.base.colors.gray.medium, 0.7));\n const { rtl } = useDirection();\n\n return css`\n position: absolute;\n z-index: 1;\n inset-block: 0;\n min-width: ${theme.base['hit-area']['mouse-min']};\n color: ${theme.base.palette['foreground-color']};\n box-shadow: none;\n border-radius: 0;\n\n @media (pointer: coarse) {\n min-width: ${theme.base['hit-area']['finger-min']};\n }\n\n &[hidden] {\n display: none;\n }\n\n & > span {\n display: inline-block;\n background-color: ${bg};\n\n ${StyledIcon} {\n color: ${theme.base.palette.light};\n width: 2rem;\n height: 3rem;\n\n ${rtl &&\n css`\n transform: rotateZ(180deg);\n `}\n }\n }\n\n &:nth-of-type(1) {\n inset-inline-start: 0;\n text-align: start;\n & > span {\n border-start-end-radius: calc(${theme.base['border-radius']} / 2);\n border-end-end-radius: calc(${theme.base['border-radius']} / 2);\n }\n }\n\n &:nth-of-type(2) {\n inset-inline-end: 0;\n text-align: end;\n & > span {\n border-start-start-radius: calc(${theme.base['border-radius']} / 2);\n border-end-start-radius: calc(${theme.base['border-radius']} / 2);\n }\n }\n\n &:hover > span {\n background-color: ${hoverBg};\n }\n\n &:focus > span {\n box-shadow: ${theme.base.shadow.focus};\n }\n `;\n});\n\nStyledNavButton.defaultProps = defaultThemeProp;\n\nexport const StyledContainer = styled.div(({ theme }) => {\n return css`\n button {\n padding: ${theme.base.spacing};\n color: ${theme.base.palette.light};\n\n &:focus:enabled {\n box-shadow: ${theme.base.shadow.focus};\n }\n }\n `;\n});\n\nStyledContainer.defaultProps = defaultThemeProp;\n\nexport const StyledMediaContainer = styled.div<{ global: boolean }>(({ theme, global }) => {\n return css`\n position: relative;\n\n ${!global &&\n css`\n background-color: ${theme.base.colors.gray['extra-dark']};\n overflow-y: auto;\n `}\n\n & > div {\n position: absolute;\n inset: 0;\n }\n\n ${StyledErrorState} {\n margin: auto;\n & > ${StyledText} {\n color: ${theme.base.palette.light};\n }\n }\n\n img,\n video,\n audio {\n display: block;\n max-width: calc(100% - 5rem);\n max-height: 100%;\n margin: auto;\n }\n\n img,\n video {\n ${!global &&\n css`\n margin-block-start: calc(${theme.base.spacing} * 4);\n max-width: calc(100% - calc(${theme.base.spacing} * 4));\n `}\n }\n `;\n});\n\nexport const StyledObject = styled.object`\n display: block;\n margin: auto;\n width: calc(100% - 5rem);\n height: 100%;\n`;\n\nStyledMediaContainer.defaultProps = defaultThemeProp;\n\nexport const StyledPreviewRegion = styled.div`\n position: relative;\n width: 100%;\n`;\n\nexport const StyledLiveRegion = styled.div`\n ${hideVisually}\n`;\n\nexport const StyledLightboxTitle = styled(Text)`\n max-width: 100%;\n ${ellipsisOverflow};\n`;\n\nexport const StyledLightbox = styled(Backdrop)<{ global: boolean }>(({ global, theme }) => {\n return css`\n ${global &&\n css`\n z-index: ${theme.base['z-index'].max};\n `}\n\n &:focus {\n outline: none;\n }\n `;\n});\n\nStyledLightbox.defaultProps = defaultThemeProp;\n"]}
|
|
1
|
+
{"version":3,"file":"Lightbox.styles.js","sourceRoot":"","sources":["../../../src/components/Lightbox/Lightbox.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,QAAQ,MAAM,aAAa,CAA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AAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAA;;;;;CAKxC,CAAC;AAEF,oBAAoB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAErD,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAA;;;CAG5C,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAA;IACtC,YAAY;CACf,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;;IAE3C,gBAAgB;CACnB,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAsB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE;IACxF,OAAO,GAAG,CAAA;MACN,MAAM;QACR,GAAG,CAAA;iBACU,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG;KACrC;;;;;GAKF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,cAAc,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\nimport { hideVisually, rgba } from 'polished';\n\nimport { defaultThemeProp } from '../../theme';\nimport { tryCatch } from '../../utils';\nimport { calculateFontSize } from '../../styles';\nimport BareButton from '../Button/BareButton';\nimport { StyledIcon } from '../Icon';\nimport { StyledMetaList } from '../MetaList/MetaList';\nimport { StyledErrorState } from '../ErrorState';\nimport Text, { StyledText } from '../Text';\nimport { useDirection } from '../../hooks';\nimport Backdrop from '../Backdrop';\nimport { StyledLink } from '../Link/Link';\nimport { ellipsisOverflow } from '../../styles/mixins';\n\nexport const StyledHeader = styled.header<{ global: boolean }>(({ theme, global }) => {\n const color: string | undefined = tryCatch(() =>\n rgba(theme.base.palette.light, theme.base.transparency['transparent-2'])\n );\n\n return css`\n position: relative;\n width: 100%;\n padding: ${theme.base.spacing};\n color: ${color};\n ${!global &&\n css`\n background-color: ${theme.base.colors.gray['extra-dark']};\n border-block-end: 0.0625rem solid ${theme.base.palette['border-line']};\n `}\n\n ${StyledMetaList} {\n justify-content: center;\n li {\n color: ${color};\n }\n }\n `;\n});\n\nStyledHeader.defaultProps = defaultThemeProp;\n\nexport const StyledCountTracker = styled.div(({ theme }) => {\n const fontSize = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n\n return css`\n font-size: ${fontSize.xs};\n text-align: center;\n min-width: calc(2 * ${theme.base['hit-area']['mouse-min']});\n\n @media (pointer: coarse) {\n min-width: calc(2 * ${theme.base['hit-area']['finger-min']});\n }\n `;\n});\n\nStyledCountTracker.defaultProps = defaultThemeProp;\n\nexport const StyledInfo = styled.div(({ theme }) => {\n return css`\n color: ${theme.base.palette.light};\n font-weight: ${theme.base['font-weight']['semi-bold']};\n min-width: 0;\n\n ${StyledLink} {\n color: inherit;\n text-decoration: underline;\n }\n `;\n});\n\nStyledInfo.defaultProps = defaultThemeProp;\n\nexport const StyledNavButton = styled(BareButton)(({ theme }) => {\n const bg = tryCatch(() => rgba(theme.base.colors.gray.medium, 0.5));\n const hoverBg = tryCatch(() => rgba(theme.base.colors.gray.medium, 0.7));\n const { rtl } = useDirection();\n\n return css`\n position: absolute;\n z-index: 1;\n inset-block: 0;\n min-width: ${theme.base['hit-area']['mouse-min']};\n color: ${theme.base.palette['foreground-color']};\n box-shadow: none;\n border-radius: 0;\n\n @media (pointer: coarse) {\n min-width: ${theme.base['hit-area']['finger-min']};\n }\n\n &[hidden] {\n display: none;\n }\n\n & > span {\n display: inline-block;\n background-color: ${bg};\n\n ${StyledIcon} {\n color: ${theme.base.palette.light};\n width: 2rem;\n height: 3rem;\n\n ${rtl &&\n css`\n transform: rotateZ(180deg);\n `}\n }\n }\n\n &:nth-of-type(1) {\n inset-inline-start: 0;\n text-align: start;\n & > span {\n border-start-end-radius: calc(${theme.base['border-radius']} / 2);\n border-end-end-radius: calc(${theme.base['border-radius']} / 2);\n }\n }\n\n &:nth-of-type(2) {\n inset-inline-end: 0;\n text-align: end;\n & > span {\n border-start-start-radius: calc(${theme.base['border-radius']} / 2);\n border-end-start-radius: calc(${theme.base['border-radius']} / 2);\n }\n }\n\n &:hover > span {\n background-color: ${hoverBg};\n }\n\n &:focus > span {\n box-shadow: ${theme.base.shadow.focus};\n }\n `;\n});\n\nStyledNavButton.defaultProps = defaultThemeProp;\n\nexport const StyledContainer = styled.div(({ theme }) => {\n return css`\n button {\n padding: ${theme.base.spacing};\n color: ${theme.base.palette.light};\n\n &:focus:enabled {\n box-shadow: ${theme.base.shadow.focus};\n }\n }\n `;\n});\n\nStyledContainer.defaultProps = defaultThemeProp;\n\nexport const StyledMediaContainer = styled.div<{ global: boolean; zoomable?: boolean }>(\n ({ theme, global, zoomable }) => {\n return css`\n position: relative;\n\n ${!global &&\n css`\n background-color: ${theme.base.colors.gray['extra-dark']};\n overflow-y: auto;\n `}\n\n & > div {\n position: absolute;\n inset: 0;\n }\n\n ${zoomable &&\n css`\n overflow: auto;\n\n &:focus-visible {\n box-shadow: ${theme.base.shadow['focus-inset']};\n }\n `}\n\n ${StyledErrorState} {\n margin: auto;\n & > ${StyledText} {\n color: ${theme.base.palette.light};\n }\n }\n\n img,\n video,\n audio {\n display: block;\n max-width: calc(100% - 5rem);\n max-height: 100%;\n margin: auto;\n }\n\n img,\n video {\n ${!global &&\n css`\n margin-block-start: calc(${theme.base.spacing} * 4);\n max-width: calc(100% - calc(${theme.base.spacing} * 4));\n `}\n }\n `;\n }\n);\n\nexport const StyledObject = styled.object`\n display: block;\n margin: auto;\n width: calc(100% - 5rem);\n height: 100%;\n`;\n\nStyledMediaContainer.defaultProps = defaultThemeProp;\n\nexport const StyledPreviewRegion = styled.div`\n position: relative;\n width: 100%;\n`;\n\nexport const StyledLiveRegion = styled.div`\n ${hideVisually}\n`;\n\nexport const StyledLightboxTitle = styled(Text)`\n max-width: 100%;\n ${ellipsisOverflow};\n`;\n\nexport const StyledLightbox = styled(Backdrop)<{ global: boolean }>(({ global, theme }) => {\n return css`\n ${global &&\n css`\n z-index: ${theme.base['z-index'].max};\n `}\n\n &:focus {\n outline: none;\n }\n `;\n});\n\nStyledLightbox.defaultProps = defaultThemeProp;\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { NoChildrenProp, TestIdProp, WithAttributes } from '../../../types';
|
|
2
|
+
export type ZoomControlsProps = WithAttributes<'div', TestIdProp & NoChildrenProp & {
|
|
3
|
+
/** Zooms in a step. */
|
|
4
|
+
onZoomIn: () => void;
|
|
5
|
+
/** Zooms out a step. */
|
|
6
|
+
onZoomOut: () => void;
|
|
7
|
+
/** Returns the target to its resting size. The reset control is only rendered when set. */
|
|
8
|
+
onReset?: () => void;
|
|
9
|
+
}>;
|
|
10
|
+
declare const _default: import("react").ForwardRefExoticComponent<Omit<ZoomControlsProps, "ref"> & import("react").RefAttributes<HTMLDivElement>> & {
|
|
11
|
+
getTestIds: (testIdProp?: TestIdProp["testId"]) => import("../../..").TestIdsRecord<readonly ["zoom-in", "zoom-out", "zoom-reset"]>;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
14
|
+
//# sourceMappingURL=ZoomControls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZoomControls.d.ts","sourceRoot":"","sources":["../../../../src/components/Lightbox/ZoomControls/ZoomControls.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAc,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAc7F,MAAM,MAAM,iBAAiB,GAAG,cAAc,CAC5C,KAAK,EACL,UAAU,GACR,cAAc,GAAG;IACf,uBAAuB;IACvB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,wBAAwB;IACxB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,2FAA2F;IAC3F,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CACJ,CAAC;;;;AAwDF,wBAAiE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useRef } from 'react';
|
|
3
|
+
import { withTestIds } from '../../../utils';
|
|
4
|
+
import { useI18n, useTestIds } from '../../../hooks';
|
|
5
|
+
import Flex from '../../Flex';
|
|
6
|
+
import Icon, { registerIcon } from '../../Icon';
|
|
7
|
+
import * as plusIcon from '../../Icon/icons/plus.icon';
|
|
8
|
+
import * as minusIcon from '../../Icon/icons/minus.icon';
|
|
9
|
+
import * as resetIcon from '../../Icon/icons/reset.icon';
|
|
10
|
+
import { StyledZoomControls, StyledZoomControlsButton } from './ZoomControls.styles';
|
|
11
|
+
import { getZoomControlsTestIds } from './ZoomControls.test-ids';
|
|
12
|
+
registerIcon(plusIcon, minusIcon, resetIcon);
|
|
13
|
+
const ZoomControls = forwardRef(function ZoomControls({ testId, onZoomIn, onZoomOut, onReset, ...restProps }, ref) {
|
|
14
|
+
const t = useI18n();
|
|
15
|
+
const testIds = useTestIds(testId, getZoomControlsTestIds);
|
|
16
|
+
const zoomInRef = useRef(null);
|
|
17
|
+
return (_jsxs(Flex, { as: StyledZoomControls, "data-testid": testIds.root, ...restProps, role: 'group', "aria-label": t('zoom_controls'), ref: ref, container: { direction: 'column', gap: 1 }, children: [onReset && (_jsx(StyledZoomControlsButton, { "data-testid": testIds.zoomReset, variant: 'simple', label: t('reset_zoom'), icon: true, onClick: () => {
|
|
18
|
+
zoomInRef.current?.focus();
|
|
19
|
+
onReset();
|
|
20
|
+
}, children: _jsx(Icon, { name: 'reset' }) })), _jsx(StyledZoomControlsButton, { ref: zoomInRef, "data-testid": testIds.zoomIn, variant: 'simple', label: t('zoom_in'), icon: true, onClick: onZoomIn, children: _jsx(Icon, { name: 'plus' }) }), _jsx(StyledZoomControlsButton, { "data-testid": testIds.zoomOut, variant: 'simple', label: t('zoom_out'), icon: true, onClick: onZoomOut, children: _jsx(Icon, { name: 'minus' }) })] }));
|
|
21
|
+
});
|
|
22
|
+
export default withTestIds(ZoomControls, getZoomControlsTestIds);
|
|
23
|
+
//# sourceMappingURL=ZoomControls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZoomControls.js","sourceRoot":"","sources":["../../../../src/components/Lightbox/ZoomControls/ZoomControls.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAI3C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAC;AACvD,OAAO,KAAK,SAAS,MAAM,6BAA6B,CAAC;AACzD,OAAO,KAAK,SAAS,MAAM,6BAA6B,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,YAAY,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAe7C,MAAM,YAAY,GAAG,UAAU,CAC7B,SAAS,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,SAAS,EAAE,EAAE,GAAG;IAC/E,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IACpB,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAC3D,MAAM,SAAS,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAElD,OAAO,CACL,MAAC,IAAI,IACH,EAAE,EAAE,kBAAkB,iBACT,OAAO,CAAC,IAAI,KACrB,SAAS,EACb,IAAI,EAAC,OAAO,gBACA,CAAC,CAAC,eAAe,CAAC,EAC9B,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,aAEzC,OAAO,IAAI,CACV,KAAC,wBAAwB,mBACV,OAAO,CAAC,SAAS,EAC9B,OAAO,EAAC,QAAQ,EAChB,KAAK,EAAE,CAAC,CAAC,YAAY,CAAC,EACtB,IAAI,QACJ,OAAO,EAAE,GAAG,EAAE;oBACZ,SAAS,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;oBAC3B,OAAO,EAAE,CAAC;gBACZ,CAAC,YAED,KAAC,IAAI,IAAC,IAAI,EAAC,OAAO,GAAG,GACI,CAC5B,EACD,KAAC,wBAAwB,IACvB,GAAG,EAAE,SAAS,iBACD,OAAO,CAAC,MAAM,EAC3B,OAAO,EAAC,QAAQ,EAChB,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC,EACnB,IAAI,QACJ,OAAO,EAAE,QAAQ,YAEjB,KAAC,IAAI,IAAC,IAAI,EAAC,MAAM,GAAG,GACK,EAC3B,KAAC,wBAAwB,mBACV,OAAO,CAAC,OAAO,EAC5B,OAAO,EAAC,QAAQ,EAChB,KAAK,EAAE,CAAC,CAAC,UAAU,CAAC,EACpB,IAAI,QACJ,OAAO,EAAE,SAAS,YAElB,KAAC,IAAI,IAAC,IAAI,EAAC,OAAO,GAAG,GACI,IACtB,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC,YAAY,EAAE,sBAAsB,CAAC,CAAC","sourcesContent":["import { forwardRef, useRef } from 'react';\nimport type { PropsWithoutRef } from 'react';\n\nimport type { NoChildrenProp, RefElement, TestIdProp, WithAttributes } from '../../../types';\nimport { withTestIds } from '../../../utils';\nimport { useI18n, useTestIds } from '../../../hooks';\nimport Flex from '../../Flex';\nimport Icon, { registerIcon } from '../../Icon';\nimport * as plusIcon from '../../Icon/icons/plus.icon';\nimport * as minusIcon from '../../Icon/icons/minus.icon';\nimport * as resetIcon from '../../Icon/icons/reset.icon';\n\nimport { StyledZoomControls, StyledZoomControlsButton } from './ZoomControls.styles';\nimport { getZoomControlsTestIds } from './ZoomControls.test-ids';\n\nregisterIcon(plusIcon, minusIcon, resetIcon);\n\nexport type ZoomControlsProps = WithAttributes<\n 'div',\n TestIdProp &\n NoChildrenProp & {\n /** Zooms in a step. */\n onZoomIn: () => void;\n /** Zooms out a step. */\n onZoomOut: () => void;\n /** Returns the target to its resting size. The reset control is only rendered when set. */\n onReset?: () => void;\n }\n>;\n\nconst ZoomControls = forwardRef<RefElement<ZoomControlsProps>, PropsWithoutRef<ZoomControlsProps>>(\n function ZoomControls({ testId, onZoomIn, onZoomOut, onReset, ...restProps }, ref) {\n const t = useI18n();\n const testIds = useTestIds(testId, getZoomControlsTestIds);\n const zoomInRef = useRef<HTMLButtonElement>(null);\n\n return (\n <Flex\n as={StyledZoomControls}\n data-testid={testIds.root}\n {...restProps}\n role='group'\n aria-label={t('zoom_controls')}\n ref={ref}\n container={{ direction: 'column', gap: 1 }}\n >\n {onReset && (\n <StyledZoomControlsButton\n data-testid={testIds.zoomReset}\n variant='simple'\n label={t('reset_zoom')}\n icon\n onClick={() => {\n zoomInRef.current?.focus();\n onReset();\n }}\n >\n <Icon name='reset' />\n </StyledZoomControlsButton>\n )}\n <StyledZoomControlsButton\n ref={zoomInRef}\n data-testid={testIds.zoomIn}\n variant='simple'\n label={t('zoom_in')}\n icon\n onClick={onZoomIn}\n >\n <Icon name='plus' />\n </StyledZoomControlsButton>\n <StyledZoomControlsButton\n data-testid={testIds.zoomOut}\n variant='simple'\n label={t('zoom_out')}\n icon\n onClick={onZoomOut}\n >\n <Icon name='minus' />\n </StyledZoomControlsButton>\n </Flex>\n );\n }\n);\n\nexport default withTestIds(ZoomControls, getZoomControlsTestIds);\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const StyledZoomControlsButton: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<Omit<Omit<import("../../Button").ButtonProps, "ref"> & import("react").RefAttributes<HTMLAnchorElement | HTMLButtonElement> & import("../../..").ForwardProps, "ref"> & {
|
|
2
|
+
ref?: ((instance: HTMLAnchorElement | HTMLButtonElement | null) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<HTMLAnchorElement | HTMLButtonElement> | null | undefined;
|
|
3
|
+
}, never>> & string & Omit<import("../../..").ForwardRefForwardPropsComponent<import("../../Button").ButtonProps>, keyof import("react").Component<any, {}, any>>;
|
|
4
|
+
export declare const StyledZoomControls: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
5
|
+
//# sourceMappingURL=ZoomControls.styles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZoomControls.styles.d.ts","sourceRoot":"","sources":["../../../../src/components/Lightbox/ZoomControls/ZoomControls.styles.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,wBAAwB;;iKAenC,CAAC;AAIH,eAAO,MAAM,kBAAkB,6NAgB7B,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
import { rgba } from 'polished';
|
|
3
|
+
import { defaultThemeProp } from '../../../theme';
|
|
4
|
+
import { tryCatch } from '../../../utils';
|
|
5
|
+
import Button from '../../Button';
|
|
6
|
+
export const StyledZoomControlsButton = styled(Button)(({ theme }) => {
|
|
7
|
+
const bg = tryCatch(() => rgba(theme.base.colors.gray.medium, 0.5));
|
|
8
|
+
const hoverBg = tryCatch(() => rgba(theme.base.colors.gray.medium, 0.7));
|
|
9
|
+
return css `
|
|
10
|
+
background-color: ${bg};
|
|
11
|
+
|
|
12
|
+
& + & {
|
|
13
|
+
margin-inline-start: 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&:hover {
|
|
17
|
+
background-color: ${hoverBg};
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
});
|
|
21
|
+
StyledZoomControlsButton.defaultProps = defaultThemeProp;
|
|
22
|
+
export const StyledZoomControls = styled.div(({ theme }) => {
|
|
23
|
+
return css `
|
|
24
|
+
position: absolute;
|
|
25
|
+
z-index: 2;
|
|
26
|
+
inset-block-end: calc(${theme.base.spacing} * 2);
|
|
27
|
+
inset-inline-end: calc(${theme.base.spacing} * 2);
|
|
28
|
+
|
|
29
|
+
${StyledZoomControlsButton} {
|
|
30
|
+
padding: ${theme.base.spacing};
|
|
31
|
+
color: ${theme.base.palette.light};
|
|
32
|
+
|
|
33
|
+
&:focus:enabled {
|
|
34
|
+
box-shadow: ${theme.base.shadow.focus};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
});
|
|
39
|
+
StyledZoomControls.defaultProps = defaultThemeProp;
|
|
40
|
+
//# sourceMappingURL=ZoomControls.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZoomControls.styles.js","sourceRoot":"","sources":["../../../../src/components/Lightbox/ZoomControls/ZoomControls.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,MAAM,MAAM,cAAc,CAAC;AAElC,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACnE,MAAM,EAAE,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IACpE,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IAEzE,OAAO,GAAG,CAAA;wBACY,EAAE;;;;;;;0BAOA,OAAO;;GAE9B,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,wBAAwB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEzD,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACzD,OAAO,GAAG,CAAA;;;4BAGgB,KAAK,CAAC,IAAI,CAAC,OAAO;6BACjB,KAAK,CAAC,IAAI,CAAC,OAAO;;MAEzC,wBAAwB;iBACb,KAAK,CAAC,IAAI,CAAC,OAAO;eACpB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK;;;sBAGjB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK;;;GAG1C,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,kBAAkB,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\nimport { rgba } from 'polished';\n\nimport { defaultThemeProp } from '../../../theme';\nimport { tryCatch } from '../../../utils';\nimport Button from '../../Button';\n\nexport const StyledZoomControlsButton = styled(Button)(({ theme }) => {\n const bg = tryCatch(() => rgba(theme.base.colors.gray.medium, 0.5));\n const hoverBg = tryCatch(() => rgba(theme.base.colors.gray.medium, 0.7));\n\n return css`\n background-color: ${bg};\n\n & + & {\n margin-inline-start: 0;\n }\n\n &:hover {\n background-color: ${hoverBg};\n }\n `;\n});\n\nStyledZoomControlsButton.defaultProps = defaultThemeProp;\n\nexport const StyledZoomControls = styled.div(({ theme }) => {\n return css`\n position: absolute;\n z-index: 2;\n inset-block-end: calc(${theme.base.spacing} * 2);\n inset-inline-end: calc(${theme.base.spacing} * 2);\n\n ${StyledZoomControlsButton} {\n padding: ${theme.base.spacing};\n color: ${theme.base.palette.light};\n\n &:focus:enabled {\n box-shadow: ${theme.base.shadow.focus};\n }\n }\n `;\n});\n\nStyledZoomControls.defaultProps = defaultThemeProp;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZoomControls.test-ids.d.ts","sourceRoot":"","sources":["../../../../src/components/Lightbox/ZoomControls/ZoomControls.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,4IAIxB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZoomControls.test-ids.js","sourceRoot":"","sources":["../../../../src/components/Lightbox/ZoomControls/ZoomControls.test-ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,CAAC,MAAM,sBAAsB,GAAG,aAAa,CAAC,eAAe,EAAE;IACnE,SAAS;IACT,UAAU;IACV,YAAY;CACJ,CAAC,CAAC","sourcesContent":["import { createTestIds } from '../../../utils';\n\nexport const getZoomControlsTestIds = createTestIds('zoom-controls', [\n 'zoom-in',\n 'zoom-out',\n 'zoom-reset'\n] as const);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Lightbox/ZoomControls/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Lightbox/ZoomControls/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["export { default } from './ZoomControls';\nexport type { ZoomControlsProps } from './ZoomControls';\nexport { StyledZoomControls, StyledZoomControlsButton } from './ZoomControls.styles';\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
interface UseZoomOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The largest allowed scale. Values below 1 are treated as 1.
|
|
4
|
+
* @default 4
|
|
5
|
+
*/
|
|
6
|
+
maxScale?: number;
|
|
7
|
+
}
|
|
8
|
+
interface UseZoomResult {
|
|
9
|
+
/** Zooms in a step, centered on the container. */
|
|
10
|
+
zoomIn: () => void;
|
|
11
|
+
/** Zooms out a step, centered on the container. */
|
|
12
|
+
zoomOut: () => void;
|
|
13
|
+
/** Returns the target to its resting size. */
|
|
14
|
+
reset: () => void;
|
|
15
|
+
/** Whether the target is currently zoomed away from its resting size. */
|
|
16
|
+
zoomed: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Adds pinch, ctrl + wheel and double tap zooming to a target element.
|
|
20
|
+
*
|
|
21
|
+
* Zooming only scales the target. Above the resting size, scrolling is left to the container,
|
|
22
|
+
* which must be scrollable, and the content under the gesture stays in place. Below the resting
|
|
23
|
+
* size, the target scales around the center of the visible area, and the scroll position is kept.
|
|
24
|
+
*
|
|
25
|
+
* @param container The scrollable element that receives gestures. Gestures are off while null.
|
|
26
|
+
* @param target The element that is scaled.
|
|
27
|
+
*/
|
|
28
|
+
declare const useZoom: (container: HTMLElement | null, target: HTMLElement | null, { maxScale }?: UseZoomOptions) => UseZoomResult;
|
|
29
|
+
export default useZoom;
|
|
30
|
+
//# sourceMappingURL=useZoom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useZoom.d.ts","sourceRoot":"","sources":["../../../src/components/Lightbox/useZoom.ts"],"names":[],"mappings":"AAgCA,UAAU,cAAc;IACtB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,aAAa;IACrB,kDAAkD;IAClD,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,mDAAmD;IACnD,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,8CAA8C;IAC9C,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,yEAAyE;IACzE,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;GASG;AACH,QAAA,MAAM,OAAO,GACX,WAAW,WAAW,GAAG,IAAI,EAC7B,QAAQ,WAAW,GAAG,IAAI,EAC1B,eAAkB,cAAmB,KACpC,aA8KF,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { clamp, isInstance } from '../../utils';
|
|
3
|
+
const ZOOM_STEP = 1.5;
|
|
4
|
+
const MIN_SCALE = 0.5;
|
|
5
|
+
const DOUBLE_TAP_SCALE = 2;
|
|
6
|
+
const DOUBLE_TAP_DELAY = 300;
|
|
7
|
+
const DOUBLE_TAP_DISTANCE = 30;
|
|
8
|
+
const TAP_MOVE_THRESHOLD = 8;
|
|
9
|
+
const WHEEL_ZOOM_SPEED = 0.01;
|
|
10
|
+
const WHEEL_MAX_DELTA = 25;
|
|
11
|
+
const LINE_HEIGHT = 16;
|
|
12
|
+
// Scaling from the top left only adds overflow at the end, so space before the target (e.g. from
|
|
13
|
+
// centering) is never matched there. Shrinks that space as the target grows to fill the container.
|
|
14
|
+
const getShift = (start, size, containerSize, scale) => {
|
|
15
|
+
const free = containerSize - size;
|
|
16
|
+
if (free <= 0)
|
|
17
|
+
return 0;
|
|
18
|
+
return -start * (1 - clamp((containerSize - size * scale) / free, 0, 1));
|
|
19
|
+
};
|
|
20
|
+
// Below the resting size, keep the center of the visible area fixed, wherever it is scrolled to.
|
|
21
|
+
const getZoomOutShift = (start, scroll, containerSize, scale) => (scroll + containerSize / 2 - start) * (1 - scale);
|
|
22
|
+
/**
|
|
23
|
+
* Adds pinch, ctrl + wheel and double tap zooming to a target element.
|
|
24
|
+
*
|
|
25
|
+
* Zooming only scales the target. Above the resting size, scrolling is left to the container,
|
|
26
|
+
* which must be scrollable, and the content under the gesture stays in place. Below the resting
|
|
27
|
+
* size, the target scales around the center of the visible area, and the scroll position is kept.
|
|
28
|
+
*
|
|
29
|
+
* @param container The scrollable element that receives gestures. Gestures are off while null.
|
|
30
|
+
* @param target The element that is scaled.
|
|
31
|
+
*/
|
|
32
|
+
const useZoom = (container, target, { maxScale = 4 } = {}) => {
|
|
33
|
+
const scale = useRef(1);
|
|
34
|
+
const shift = useRef({ x: 0, y: 0 });
|
|
35
|
+
const [scaleState, setScaleState] = useState(1);
|
|
36
|
+
const reset = useCallback(() => {
|
|
37
|
+
scale.current = 1;
|
|
38
|
+
shift.current = { x: 0, y: 0 };
|
|
39
|
+
setScaleState(1);
|
|
40
|
+
if (!target)
|
|
41
|
+
return;
|
|
42
|
+
target.style.transform = '';
|
|
43
|
+
target.style.transformOrigin = '';
|
|
44
|
+
}, [target]);
|
|
45
|
+
const zoomTo = useCallback((nextScale, point) => {
|
|
46
|
+
const next = clamp(nextScale, MIN_SCALE, Math.max(1, maxScale));
|
|
47
|
+
if (!container || !target || next === scale.current)
|
|
48
|
+
return;
|
|
49
|
+
const zoomedOut = next < 1;
|
|
50
|
+
const rect = target.getBoundingClientRect();
|
|
51
|
+
const bounds = container.getBoundingClientRect();
|
|
52
|
+
const current = scale.current;
|
|
53
|
+
// The target's unscaled position within the container's scrollable content.
|
|
54
|
+
const startX = rect.left - bounds.left + container.scrollLeft - shift.current.x;
|
|
55
|
+
const startY = rect.top - bounds.top + container.scrollTop - shift.current.y;
|
|
56
|
+
const width = rect.width / current;
|
|
57
|
+
const height = rect.height / current;
|
|
58
|
+
const previousShift = shift.current;
|
|
59
|
+
const nextShift = zoomedOut
|
|
60
|
+
? {
|
|
61
|
+
x: getZoomOutShift(startX, container.scrollLeft, container.clientWidth, next),
|
|
62
|
+
y: getZoomOutShift(startY, container.scrollTop, container.clientHeight, next)
|
|
63
|
+
}
|
|
64
|
+
: {
|
|
65
|
+
x: getShift(startX, width, container.clientWidth, next),
|
|
66
|
+
y: getShift(startY, height, container.clientHeight, next)
|
|
67
|
+
};
|
|
68
|
+
scale.current = next;
|
|
69
|
+
shift.current = nextShift;
|
|
70
|
+
setScaleState(next);
|
|
71
|
+
target.style.transformOrigin = next === 1 ? '' : '0 0';
|
|
72
|
+
target.style.transform =
|
|
73
|
+
next === 1 ? '' : `translate(${nextShift.x}px, ${nextShift.y}px) scale(${next})`;
|
|
74
|
+
if (zoomedOut)
|
|
75
|
+
return;
|
|
76
|
+
const origin = point ?? {
|
|
77
|
+
x: (bounds.left + bounds.right) / 2,
|
|
78
|
+
y: (bounds.top + bounds.bottom) / 2
|
|
79
|
+
};
|
|
80
|
+
const growth = next / current - 1;
|
|
81
|
+
const scrollX = growth * (origin.x - rect.left) + nextShift.x - previousShift.x;
|
|
82
|
+
const scrollY = growth * (origin.y - rect.top) + nextShift.y - previousShift.y;
|
|
83
|
+
container.scrollLeft += scrollX;
|
|
84
|
+
container.scrollTop += scrollY;
|
|
85
|
+
}, [container, target, maxScale]);
|
|
86
|
+
const zoomIn = useCallback(() => zoomTo(scale.current * ZOOM_STEP), [zoomTo]);
|
|
87
|
+
const zoomOut = useCallback(() => zoomTo(scale.current / ZOOM_STEP), [zoomTo]);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (!container)
|
|
90
|
+
return;
|
|
91
|
+
const pointers = new Map();
|
|
92
|
+
let tap;
|
|
93
|
+
let lastTap;
|
|
94
|
+
// Allows native scrolling, but not the browser's own pinch zoom.
|
|
95
|
+
const previousTouchAction = container.style.touchAction;
|
|
96
|
+
container.style.touchAction = 'pan-x pan-y';
|
|
97
|
+
const measure = () => {
|
|
98
|
+
const [a, b] = [...pointers.values()];
|
|
99
|
+
return {
|
|
100
|
+
mid: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 },
|
|
101
|
+
distance: Math.hypot(a.x - b.x, a.y - b.y)
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
const onWheel = (e) => {
|
|
105
|
+
// Trackpad pinches arrive as ctrl + wheel in Chromium and Firefox.
|
|
106
|
+
if (!e.ctrlKey)
|
|
107
|
+
return;
|
|
108
|
+
e.preventDefault();
|
|
109
|
+
const delta = clamp(e.deltaY * (e.deltaMode === 1 ? LINE_HEIGHT : 1), -WHEEL_MAX_DELTA, WHEEL_MAX_DELTA);
|
|
110
|
+
zoomTo(scale.current * Math.exp(-delta * WHEEL_ZOOM_SPEED), { x: e.clientX, y: e.clientY });
|
|
111
|
+
};
|
|
112
|
+
const onPointerDown = (e) => {
|
|
113
|
+
if ((e.pointerType === 'mouse' && e.button !== 0) || pointers.size >= 2)
|
|
114
|
+
return;
|
|
115
|
+
container.setPointerCapture(e.pointerId);
|
|
116
|
+
pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
117
|
+
tap =
|
|
118
|
+
pointers.size === 1
|
|
119
|
+
? {
|
|
120
|
+
id: e.pointerId,
|
|
121
|
+
x: e.clientX,
|
|
122
|
+
y: e.clientY,
|
|
123
|
+
onTarget: !!target && isInstance(e.target, Node) && target.contains(e.target)
|
|
124
|
+
}
|
|
125
|
+
: undefined;
|
|
126
|
+
};
|
|
127
|
+
const onPointerMove = (e) => {
|
|
128
|
+
if (!pointers.has(e.pointerId))
|
|
129
|
+
return;
|
|
130
|
+
const before = pointers.size === 2 ? measure() : undefined;
|
|
131
|
+
pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
132
|
+
if (tap && Math.hypot(e.clientX - tap.x, e.clientY - tap.y) > TAP_MOVE_THRESHOLD) {
|
|
133
|
+
tap = undefined;
|
|
134
|
+
}
|
|
135
|
+
if (before && before.distance > 0) {
|
|
136
|
+
const after = measure();
|
|
137
|
+
zoomTo((scale.current * after.distance) / before.distance, after.mid);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const onPointerEnd = (e) => {
|
|
141
|
+
if (!pointers.delete(e.pointerId))
|
|
142
|
+
return;
|
|
143
|
+
const completedTap = e.type === 'pointerup' && tap?.id === e.pointerId ? tap : undefined;
|
|
144
|
+
tap = undefined;
|
|
145
|
+
if (!completedTap?.onTarget)
|
|
146
|
+
return;
|
|
147
|
+
const point = { x: e.clientX, y: e.clientY };
|
|
148
|
+
if (lastTap &&
|
|
149
|
+
e.timeStamp - lastTap.time < DOUBLE_TAP_DELAY &&
|
|
150
|
+
Math.hypot(point.x - lastTap.x, point.y - lastTap.y) < DOUBLE_TAP_DISTANCE) {
|
|
151
|
+
lastTap = undefined;
|
|
152
|
+
if (scale.current !== 1)
|
|
153
|
+
reset();
|
|
154
|
+
else
|
|
155
|
+
zoomTo(DOUBLE_TAP_SCALE, point);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
lastTap = { ...point, time: e.timeStamp };
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const ac = new AbortController();
|
|
162
|
+
// Non-passive so wheel events can cancel the browser's page zoom.
|
|
163
|
+
const listenerOptions = { passive: false, signal: ac.signal };
|
|
164
|
+
container.addEventListener('wheel', onWheel, listenerOptions);
|
|
165
|
+
container.addEventListener('pointerdown', onPointerDown, listenerOptions);
|
|
166
|
+
container.addEventListener('pointermove', onPointerMove, listenerOptions);
|
|
167
|
+
container.addEventListener('pointerup', onPointerEnd, listenerOptions);
|
|
168
|
+
container.addEventListener('pointercancel', onPointerEnd, listenerOptions);
|
|
169
|
+
return () => {
|
|
170
|
+
ac.abort();
|
|
171
|
+
container.style.touchAction = previousTouchAction;
|
|
172
|
+
reset();
|
|
173
|
+
};
|
|
174
|
+
}, [container, target, zoomTo, reset]);
|
|
175
|
+
return {
|
|
176
|
+
zoomIn,
|
|
177
|
+
zoomOut,
|
|
178
|
+
reset,
|
|
179
|
+
zoomed: scaleState !== 1
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
export default useZoom;
|
|
183
|
+
//# sourceMappingURL=useZoom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useZoom.js","sourceRoot":"","sources":["../../../src/components/Lightbox/useZoom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOhD,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB,iGAAiG;AACjG,mGAAmG;AACnG,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAE,IAAY,EAAE,aAAqB,EAAE,KAAa,EAAE,EAAE;IACrF,MAAM,IAAI,GAAG,aAAa,GAAG,IAAI,CAAC;IAClC,IAAI,IAAI,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IAExB,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,aAAa,GAAG,IAAI,GAAG,KAAK,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC3E,CAAC,CAAC;AAEF,i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EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAEvC,OAAO;QACL,MAAM;QACN,OAAO;QACP,KAAK;QACL,MAAM,EAAE,UAAU,KAAK,CAAC;KACzB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,OAAO,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { clamp, isInstance } from '../../utils';\n\ninterface Point {\n x: number;\n y: number;\n}\n\nconst ZOOM_STEP = 1.5;\nconst MIN_SCALE = 0.5;\nconst DOUBLE_TAP_SCALE = 2;\nconst DOUBLE_TAP_DELAY = 300;\nconst DOUBLE_TAP_DISTANCE = 30;\nconst TAP_MOVE_THRESHOLD = 8;\nconst WHEEL_ZOOM_SPEED = 0.01;\nconst WHEEL_MAX_DELTA = 25;\nconst LINE_HEIGHT = 16;\n\n// Scaling from the top left only adds overflow at the end, so space before the target (e.g. from\n// centering) is never matched there. Shrinks that space as the target grows to fill the container.\nconst getShift = (start: number, size: number, containerSize: number, scale: number) => {\n const free = containerSize - size;\n if (free <= 0) return 0;\n\n return -start * (1 - clamp((containerSize - size * scale) / free, 0, 1));\n};\n\n// Below the resting size, keep the center of the visible area fixed, wherever it is scrolled to.\nconst getZoomOutShift = (start: number, scroll: number, containerSize: number, scale: number) =>\n (scroll + containerSize / 2 - start) * (1 - scale);\n\ninterface UseZoomOptions {\n /**\n * The largest allowed scale. Values below 1 are treated as 1.\n * @default 4\n */\n maxScale?: number;\n}\n\ninterface UseZoomResult {\n /** Zooms in a step, centered on the container. */\n zoomIn: () => void;\n /** Zooms out a step, centered on the container. */\n zoomOut: () => void;\n /** Returns the target to its resting size. */\n reset: () => void;\n /** Whether the target is currently zoomed away from its resting size. */\n zoomed: boolean;\n}\n\n/**\n * Adds pinch, ctrl + wheel and double tap zooming to a target element.\n *\n * Zooming only scales the target. Above the resting size, scrolling is left to the container,\n * which must be scrollable, and the content under the gesture stays in place. Below the resting\n * size, the target scales around the center of the visible area, and the scroll position is kept.\n *\n * @param container The scrollable element that receives gestures. Gestures are off while null.\n * @param target The element that is scaled.\n */\nconst useZoom = (\n container: HTMLElement | null,\n target: HTMLElement | null,\n { maxScale = 4 }: UseZoomOptions = {}\n): UseZoomResult => {\n const scale = useRef(1);\n const shift = useRef<Point>({ x: 0, y: 0 });\n const [scaleState, setScaleState] = useState(1);\n\n const reset = useCallback(() => {\n scale.current = 1;\n shift.current = { x: 0, y: 0 };\n setScaleState(1);\n if (!target) return;\n\n target.style.transform = '';\n target.style.transformOrigin = '';\n }, [target]);\n\n const zoomTo = useCallback(\n (nextScale: number, point?: Point) => {\n const next = clamp(nextScale, MIN_SCALE, Math.max(1, maxScale));\n if (!container || !target || next === scale.current) return;\n\n const zoomedOut = next < 1;\n const rect = target.getBoundingClientRect();\n const bounds = container.getBoundingClientRect();\n const current = scale.current;\n // The target's unscaled position within the container's scrollable content.\n const startX = rect.left - bounds.left + container.scrollLeft - shift.current.x;\n const startY = rect.top - bounds.top + container.scrollTop - shift.current.y;\n const width = rect.width / current;\n const height = rect.height / current;\n const previousShift = shift.current;\n const nextShift = zoomedOut\n ? {\n x: getZoomOutShift(startX, container.scrollLeft, container.clientWidth, next),\n y: getZoomOutShift(startY, container.scrollTop, container.clientHeight, next)\n }\n : {\n x: getShift(startX, width, container.clientWidth, next),\n y: getShift(startY, height, container.clientHeight, next)\n };\n\n scale.current = next;\n shift.current = nextShift;\n setScaleState(next);\n target.style.transformOrigin = next === 1 ? '' : '0 0';\n target.style.transform =\n next === 1 ? '' : `translate(${nextShift.x}px, ${nextShift.y}px) scale(${next})`;\n if (zoomedOut) return;\n\n const origin = point ?? {\n x: (bounds.left + bounds.right) / 2,\n y: (bounds.top + bounds.bottom) / 2\n };\n const growth = next / current - 1;\n const scrollX = growth * (origin.x - rect.left) + nextShift.x - previousShift.x;\n const scrollY = growth * (origin.y - rect.top) + nextShift.y - previousShift.y;\n\n container.scrollLeft += scrollX;\n container.scrollTop += scrollY;\n },\n [container, target, maxScale]\n );\n\n const zoomIn = useCallback(() => zoomTo(scale.current * ZOOM_STEP), [zoomTo]);\n const zoomOut = useCallback(() => zoomTo(scale.current / ZOOM_STEP), [zoomTo]);\n\n useEffect(() => {\n if (!container) return;\n\n const pointers = new Map<number, Point>();\n let tap: { id: number; x: number; y: number; onTarget: boolean } | undefined;\n let lastTap: { x: number; y: number; time: number } | undefined;\n\n // Allows native scrolling, but not the browser's own pinch zoom.\n const previousTouchAction = container.style.touchAction;\n container.style.touchAction = 'pan-x pan-y';\n\n const measure = () => {\n const [a, b] = [...pointers.values()];\n\n return {\n mid: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 },\n distance: Math.hypot(a.x - b.x, a.y - b.y)\n };\n };\n\n const onWheel = (e: WheelEvent) => {\n // Trackpad pinches arrive as ctrl + wheel in Chromium and Firefox.\n if (!e.ctrlKey) return;\n\n e.preventDefault();\n const delta = clamp(\n e.deltaY * (e.deltaMode === 1 ? LINE_HEIGHT : 1),\n -WHEEL_MAX_DELTA,\n WHEEL_MAX_DELTA\n );\n zoomTo(scale.current * Math.exp(-delta * WHEEL_ZOOM_SPEED), { x: e.clientX, y: e.clientY });\n };\n\n const onPointerDown = (e: PointerEvent) => {\n if ((e.pointerType === 'mouse' && e.button !== 0) || pointers.size >= 2) return;\n\n container.setPointerCapture(e.pointerId);\n pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });\n\n tap =\n pointers.size === 1\n ? {\n id: e.pointerId,\n x: e.clientX,\n y: e.clientY,\n onTarget: !!target && isInstance(e.target, Node) && target.contains(e.target)\n }\n : undefined;\n };\n\n const onPointerMove = (e: PointerEvent) => {\n if (!pointers.has(e.pointerId)) return;\n\n const before = pointers.size === 2 ? measure() : undefined;\n pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });\n\n if (tap && Math.hypot(e.clientX - tap.x, e.clientY - tap.y) > TAP_MOVE_THRESHOLD) {\n tap = undefined;\n }\n\n if (before && before.distance > 0) {\n const after = measure();\n zoomTo((scale.current * after.distance) / before.distance, after.mid);\n }\n };\n\n const onPointerEnd = (e: PointerEvent) => {\n if (!pointers.delete(e.pointerId)) return;\n\n const completedTap = e.type === 'pointerup' && tap?.id === e.pointerId ? tap : undefined;\n tap = undefined;\n if (!completedTap?.onTarget) return;\n\n const point = { x: e.clientX, y: e.clientY };\n if (\n lastTap &&\n e.timeStamp - lastTap.time < DOUBLE_TAP_DELAY &&\n Math.hypot(point.x - lastTap.x, point.y - lastTap.y) < DOUBLE_TAP_DISTANCE\n ) {\n lastTap = undefined;\n if (scale.current !== 1) reset();\n else zoomTo(DOUBLE_TAP_SCALE, point);\n } else {\n lastTap = { ...point, time: e.timeStamp };\n }\n };\n\n const ac = new AbortController();\n // Non-passive so wheel events can cancel the browser's page zoom.\n const listenerOptions = { passive: false, signal: ac.signal };\n container.addEventListener('wheel', onWheel, listenerOptions);\n container.addEventListener('pointerdown', onPointerDown, listenerOptions);\n container.addEventListener('pointermove', onPointerMove, listenerOptions);\n container.addEventListener('pointerup', onPointerEnd, listenerOptions);\n container.addEventListener('pointercancel', onPointerEnd, listenerOptions);\n\n return () => {\n ac.abort();\n container.style.touchAction = previousTouchAction;\n reset();\n };\n }, [container, target, zoomTo, reset]);\n\n return {\n zoomIn,\n zoomOut,\n reset,\n zoomed: scaleState !== 1\n };\n};\n\nexport default useZoom;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiStepForm.d.ts","sourceRoot":"","sources":["../../../src/components/MultiStepForm/MultiStepForm.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAWnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAIhE,eAAO,MAAM,UAAU;cAA2B,OAAO;cAAY,OAAO;YAuB3E,CAAC;AAIF,eAAO,MAAM,iBAAiB,6NAAe,CAAC;AAE9C,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oLAIjC,CAAC;AAEF,eAAO,MAAM,yBAAyB;;uIAqBpC,CAAC;AAIH,QAAA,MAAM,aAAa,EAAE,+BAA+B,CAAC,kBAAkB,
|
|
1
|
+
{"version":3,"file":"MultiStepForm.d.ts","sourceRoot":"","sources":["../../../src/components/MultiStepForm/MultiStepForm.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAWnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAIhE,eAAO,MAAM,UAAU;cAA2B,OAAO;cAAY,OAAO;YAuB3E,CAAC;AAIF,eAAO,MAAM,iBAAiB,6NAAe,CAAC;AAE9C,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oLAIjC,CAAC;AAEF,eAAO,MAAM,yBAAyB;;uIAqBpC,CAAC;AAIH,QAAA,MAAM,aAAa,EAAE,+BAA+B,CAAC,kBAAkB,CA+MtE,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -123,13 +123,6 @@ const MultiStepForm = forwardRef(function MultiStepForm({ currentStepId, steps,
|
|
|
123
123
|
setFocus();
|
|
124
124
|
}
|
|
125
125
|
}, [currentStepId, previousId]);
|
|
126
|
-
// Set focus if the form content updates while focus is within the actions region of the form
|
|
127
|
-
useAfterInitialEffect(() => {
|
|
128
|
-
if (multiStepActionsRef.current &&
|
|
129
|
-
multiStepActionsRef.current.contains(document.activeElement)) {
|
|
130
|
-
setFocus();
|
|
131
|
-
}
|
|
132
|
-
}, [currentStep.content]);
|
|
133
126
|
// Set focus if a progress state resolves
|
|
134
127
|
useAfterInitialEffect(() => {
|
|
135
128
|
if (!progress) {
|