1- import { useReducer , useEffect , useMemo } from "react" ;
2- import { assert } from "tsafe/assert" ;
3- import { breakpoints , type BreakpointKeys , type BreakpointsValues } from "./fr/breakpoints" ;
1+ import { type BreakpointKeys , type BreakpointsValues } from "./fr/breakpoints" ;
2+ import { useBreakpointsValuesPx } from "./useBreakpointsValuesPx" ;
43
54export type { BreakpointKeys , BreakpointsValues } ;
65
76/** @deprecated Use import { useBreakpointsValuesPx } from "@codegouvfr/react-dsfr/useBreakpointsValuesPx"; instead */
8- export function useBreakpointsValues ( ) {
9- const [ breakpointsValuesDependency , triggerRefresh ] = useReducer ( ( ) => ( { } ) , { } ) ;
10-
11- useEffect ( ( ) => {
12- const htmlElement = document . querySelector ( "html" ) ;
13-
14- assert ( htmlElement !== null ) ;
15-
16- // Create a new MutationObserver to detect changes in the base font size
17- const observer = new MutationObserver ( mutationsList => {
18- if (
19- mutationsList . find (
20- mutation =>
21- mutation . target === htmlElement &&
22- mutation . attributeName === "style" &&
23- ( mutation . oldValue ?? "" ) . indexOf ( "font-size" ) !== - 1
24- ) !== undefined
25- ) {
26- triggerRefresh ( ) ;
27- }
28- } ) ;
29-
30- // Observe changes to the style attribute of the html element
31- observer . observe ( htmlElement , {
32- "attributes" : true ,
33- "attributeOldValue" : true ,
34- "attributeFilter" : [ "style" ]
35- } ) ;
36-
37- return ( ) => {
38- observer . disconnect ( ) ;
39- } ;
40- } , [ ] ) ;
41-
42- const breakpointsValues = useMemo (
43- ( ) => breakpoints . getBreakpointsValues ( ) ,
44- [ breakpointsValuesDependency ]
45- ) ;
46-
47- return { breakpointsValues } ;
48- }
7+ export const useBreakpointsValues = useBreakpointsValuesPx ;
0 commit comments