@@ -3,7 +3,7 @@ import type { Meta } from '@storybook/react-webpack5'
33
44import { waitFor , within , userEvent , expect } from 'storybook/test'
55
6- import Zoom , { UncontrolledProps } from '../source'
6+ import Zoom , { type UncontrolledProps } from '../source'
77import '../source/styles.css'
88import './base.css'
99
@@ -45,11 +45,17 @@ function shuffle<T extends unknown[]>(xs: T): T {
4545// =============================================================================
4646
4747export const Regular = ( props : typeof Zoom ) => {
48+ const handleZoomChange = React . useCallback <
49+ NonNullable < React . ComponentProps < typeof Zoom > [ 'onZoomChange' ] >
50+ > ( ( value , { event } ) => {
51+ console . log ( 'handleZoomChange info!' , { value, event } )
52+ } , [ ] )
53+
4854 return (
4955 < main aria-label = "Story" >
5056 < h1 > Zooming a regular image</ h1 >
5157 < div className = "mw-600" style = { { display : 'flex' , flexDirection : 'column' } } >
52- < Zoom { ...props } wrapElement = "span" >
58+ < Zoom { ...props } onZoomChange = { handleZoomChange } wrapElement = "span" >
5359 < img
5460 alt = { imgThatWanakaTree . alt }
5561 src = { imgThatWanakaTree . src }
@@ -734,6 +740,90 @@ export const SwipeToUnzoomThreshold = (props: typeof Zoom) => (
734740 </ main >
735741)
736742
743+ // =============================================================================
744+
745+ export const SelectCards = ( props : typeof Zoom ) => {
746+ return (
747+ < main aria-label = "Story" >
748+ < h1 > Selecting cards and zooming without triggering selection state</ h1 >
749+ < div className = "mw-600" style = { { display : 'flex' , flexDirection : 'column' } } >
750+ < ul className = "cards" >
751+ < CardItem
752+ alt = { imgThatWanakaTree . alt }
753+ src = { imgThatWanakaTree . src }
754+ zoomProps = { props }
755+ />
756+ < CardItem
757+ alt = { imgGlenorchyLagoon . alt }
758+ src = { imgGlenorchyLagoon . src }
759+ zoomProps = { props }
760+ />
761+ </ ul >
762+ </ div >
763+ </ main >
764+ )
765+ }
766+
767+ function CardItem ( {
768+ alt,
769+ src,
770+ zoomProps,
771+ } : {
772+ alt : string ,
773+ src : string ,
774+ zoomProps : typeof Zoom ,
775+ } ) {
776+ const [ isSelected , setIsSelected ] = React . useState ( false )
777+
778+ const handleItemClick = React . useCallback ( ( ) => {
779+ setIsSelected ( isSelected => ! isSelected )
780+ } , [ ] )
781+
782+ const handleInputClick : React . MouseEventHandler < HTMLInputElement > = React . useCallback ( ( e ) => {
783+ e . stopPropagation ( )
784+ } , [ ] )
785+
786+ const handleInputChange : React . ChangeEventHandler < HTMLInputElement > = React . useCallback ( ( e ) => {
787+ setIsSelected ( e . currentTarget . checked )
788+ } , [ ] )
789+
790+ const handleZoomChange = React . useCallback <
791+ NonNullable < React . ComponentProps < typeof Zoom > [ 'onZoomChange' ] >
792+ > ( ( value , { event } ) => {
793+ event . stopPropagation ( )
794+
795+ console . log (
796+ 'handleZoomChange (after event.stopPropagation())' ,
797+ { value, event }
798+ )
799+ } , [ ] )
800+
801+ return (
802+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
803+ < li className = "card" onClick = { handleItemClick } >
804+ < label >
805+ < input
806+ aria-label = "Select item"
807+ checked = { isSelected }
808+ onChange = { handleInputChange }
809+ onClick = { handleInputClick }
810+ type = "checkbox"
811+ />
812+ </ label >
813+ < Zoom { ...zoomProps } onZoomChange = { handleZoomChange } wrapElement = "span" >
814+ < img
815+ alt = { alt }
816+ src = { src }
817+ height = "320"
818+ width = "320"
819+ decoding = "async"
820+ loading = "lazy"
821+ />
822+ </ Zoom >
823+ </ li >
824+ )
825+ }
826+
737827// =============================================================================
738828// INTERACTIONS
739829
0 commit comments