1 | import { createContext, useContext } from 'react';
|
2 | import { useShopConfig } from '../hooks/useShopConfig';
|
3 |
|
4 |
|
5 | const BreakpointContext = createContext('sm');
|
6 | export function BreakpointConsumer({ children }) {
|
7 | const { theme: { breakpoints } } = useShopConfig();
|
8 | const breakpoint = useContext(BreakpointContext);
|
9 | const labels = Object.keys(breakpoints);
|
10 | const breakpointIndex = labels.indexOf(breakpoint);
|
11 | return children({
|
12 | breakpointIndex,
|
13 | breakpointLabel: breakpoint
|
14 | });
|
15 | }
|
16 | export function useInitialBreakpoint() {
|
17 | const { theme: { breakpoints } } = useShopConfig();
|
18 | const breakpoint = useContext(BreakpointContext);
|
19 | const labels = Object.keys(breakpoints);
|
20 | const breakpointIndex = labels.indexOf(breakpoint);
|
21 | return { breakpointIndex, breakpointLabel: breakpoint };
|
22 | }
|
23 | export const BreakpointProvider = BreakpointContext.Provider;
|
24 |
|
\ | No newline at end of file |