@@ -69,39 +69,35 @@ values.
6969import React from ' react' ;
7070import { BreakpointProvider , useBreakpoint } from ' my-breakpoint-package' ;
7171
72+
73+
7274const breakpoints = {
73- XS: 0 ,
74- SM: 500 ,
75- MD: 700 ,
76- LG: 900 ,
77- XL: 1100 ,
75+ XS: 0 , SM: 500 , MD: 700 , LG: 900 , XL: 1100 ,
7876};
7977
8078const ResponsiveComponent = () => {
8179 const { width, breakpoint, isAtLeast, valueByBreakpoint } = useBreakpoint ();
82- return (
83- <div >
84- <p >Current width : {width}px </p >
85- <p >Active breakpoint : {breakpoint}</p >
86- <p >Is at least MD : {isAtLeast(' MD' ) ? '✅' : '❌'}</p >
87- <p >
88- Mapping : {valueByBreakpoint({
89- XS : ' Extra Small' ,
90- SM : ' Small' ,
91- MD : ' Medium' ,
92- LG : ' Large' ,
93- XL : ' Extra Large'
94- })}
95- < / p >
96- < / div >
97- );
80+ return (<div ><p >Current
81+ width : {width }
82+ px < / p > < p > Active
83+ breakpoint : {breakpoint }
84+ < / p > < p > Is
85+ at
86+ least
87+ MD : {isAtLeast(' MD' ) ? '✅' : '❌'}
88+ < / p > < p > Mapping
89+ :
90+ {
91+ valueByBreakpoint({
92+ XS : ' Extra Small' , SM : ' Small' , MD : ' Medium' , LG : ' Large' , XL : ' Extra Large'
93+ })
94+ }
95+ < / p> < / div >
96+ )
97+ ;
9898};
9999
100- const App = () => (
101- < BreakpointProvider breakpoints = {breakpoints }>
102- < ResponsiveComponent / >
103- < / BreakpointProvider >
104- );
100+ const App = () => (<BreakpointProvider breakpoints = { breakpoints } > <ResponsiveComponent / > </BreakpointProvider >);
105101
106102export default App ;
107103```
@@ -116,30 +112,30 @@ Render content only when specific breakpoint conditions are met.
116112import React from ' react' ;
117113import { BreakpointProvider , BreakpointConditional } from ' my-breakpoint-package' ;
118114
115+
116+
119117const breakpoints = {
120- XS: 0 ,
121- SM: 500 ,
122- MD: 700 ,
123- LG: 900 ,
124- XL: 1100 ,
118+ XS: 0 , SM: 500 , MD: 700 , LG: 900 , XL: 1100 ,
125119};
126120
127- const ConditionalComponent = () => (
128- <div >
129- < BreakpointConditional isAtLeast = " MD" >
130- <p >😊 This content is visible from MD and up .< / p >
131- < / BreakpointConditional >
132- < BreakpointConditional isBelow = " LG" >
133- <p >🚀 This content is visible for breakpoints below LG .< / p >
134- < / BreakpointConditional >
135- < / div >
136- );
137-
138- const App = () => (
139- < BreakpointProvider breakpoints = {breakpoints }>
140- < ConditionalComponent / >
141- < / BreakpointProvider >
142- );
121+ const ConditionalComponent = () => (<div ><BreakpointConditional isAtLeast = " MD" > <p >😊 This
122+ content
123+ is
124+ visible
125+ from
126+ MD
127+ and
128+ up . < / p > < /BreakpointConditional > < BreakpointConditional
129+ isBelow = " LG" > <p >🚀 This
130+ content
131+ is
132+ visible
133+ for breakpoints below
134+ LG . < / p > < /BreakpointConditional > < /div >
135+ )
136+ ;
137+
138+ const App = () => (<BreakpointProvider breakpoints = { breakpoints } > <ConditionalComponent / > </BreakpointProvider >);
143139
144140export default App ;
145141```
@@ -154,37 +150,32 @@ Define your own custom breakpoints – for example, using car sizes:
154150import React from ' react' ;
155151import { BreakpointProvider , useBreakpoint } from ' my-breakpoint-package' ;
156152
153+
154+
157155const carBreakpoints = {
158- Smart: 0 ,
159- Mini: 350 ,
160- Sedan: 600 ,
161- SUV: 900 ,
162- Ram: 1200 ,
156+ Smart: 0 , Mini: 350 , Sedan: 600 , SUV: 900 , Ram: 1200 ,
163157};
164158
165159const CarComponent = () => {
166160 const { width, breakpoint, valueByBreakpoint } = useBreakpoint ();
167- return (
168- < div >
169- < p > Current width : {width} px </ p >
170- < p > Active car size : {breakpoint}</ p >
171- < p >
172- Mapping : {valueByBreakpoint({
173- Smart : ' 🚗 Smart ' ,
174- Mini : ' 🚙 Mini ' ,
175- Sedan : ' 🚘 Sedan ' ,
176- SUV : ' 🚐 SUV' ,
177- Ram : ' 🚚 Ram '
178- })}
179- < / p >
180- < / div >
181- ) ;
161+ return (< div >< p > Current
162+ width : { width }
163+ px < / p > < p > Active
164+ car
165+ size : { breakpoint }
166+ < / p > < p > Mapping
167+ :
168+ {
169+ valueByBreakpoint({
170+ Smart : ' 🚗 Smart ' , Mini : ' 🚙 Mini ' , Sedan : ' 🚘 Sedan ' , SUV : ' 🚐 SUV' , Ram : ' 🚚 Ram '
171+ })
172+ }
173+ < / p> < / div >
174+ )
175+ ;
182176};
183177
184- const App = () => ( <BreakpointProvider breakpoints = {carBreakpoints}>
185- <CarComponent />
186- </BreakpointProvider >
187- );
178+ const App = () => (<BreakpointProvider breakpoints = { carBreakpoints } > <CarComponent / > </BreakpointProvider >);
188179
189180export default App ;
190181```
@@ -245,39 +236,35 @@ The `useBreakpoint` hook provides access to the responsive context. It returns a
245236import React from ' react' ;
246237import { BreakpointProvider , useBreakpoint } from ' my-breakpoint-package' ;
247238
239+
240+
248241const breakpoints = {
249- XS: 0 ,
250- SM: 500 ,
251- MD: 700 ,
252- LG: 900 ,
253- XL: 1100 ,
242+ XS: 0 , SM: 500 , MD: 700 , LG: 900 , XL: 1100 ,
254243};
255244
256245const ResponsiveComponent = () => {
257246 const { width, breakpoint, isAtLeast, valueByBreakpoint } = useBreakpoint ();
258- return (
259- <div >
260- <p >Current width : {width}px </p >
261- <p >Active breakpoint : {breakpoint}</p >
262- <p >Is at least MD : {isAtLeast(' MD' ) ? '✅' : '❌'}</p >
263- <p >
264- Mapping : {valueByBreakpoint({
265- XS : ' Extra Small' ,
266- SM : ' Small' ,
267- MD : ' Medium' ,
268- LG : ' Large' ,
269- XL : ' Extra Large' ,
270- })}
271- < / p >
272- < / div >
273- );
247+ return (<div ><p >Current
248+ width : {width }
249+ px < / p > < p > Active
250+ breakpoint : {breakpoint }
251+ < / p > < p > Is
252+ at
253+ least
254+ MD : {isAtLeast(' MD' ) ? '✅' : '❌'}
255+ < / p > < p > Mapping
256+ :
257+ {
258+ valueByBreakpoint({
259+ XS : ' Extra Small' , SM : ' Small' , MD : ' Medium' , LG : ' Large' , XL : ' Extra Large' ,
260+ })
261+ }
262+ < / p> < / div >
263+ )
264+ ;
274265};
275266
276- const App = () => (
277- < BreakpointProvider breakpoints = {breakpoints }>
278- < ResponsiveComponent / >
279- < / BreakpointProvider >
280- );
267+ const App = () => (<BreakpointProvider breakpoints = { breakpoints } > <ResponsiveComponent / > </BreakpointProvider >);
281268
282269export default App ;
283270```
0 commit comments