|
1 | 1 | import type { BreakpointKeys } from "./generatedFromCss/breakpoints"; |
2 | 2 | import { |
3 | | - BreakpointsValues as values, |
4 | | - BreakpointsValuesUnit as unit, |
| 3 | + breakpointsValues as values, |
| 4 | + breakpointsValuesUnit as unit, |
5 | 5 | breakpointKeys as keys |
6 | 6 | } from "./generatedFromCss/breakpoints"; |
7 | 7 | import { type Equals, assert } from "tsafe/assert"; |
@@ -43,21 +43,62 @@ export const breakpoints = { |
43 | 43 | .between(key, keys[keys.indexOf(key) + 1]) |
44 | 44 | .replace("@media", "@media not all and"); |
45 | 45 | }, |
| 46 | + "values": (() => { |
| 47 | + const out = { |
| 48 | + ...(() => { |
| 49 | + const key = "xs" satisfies BreakpointKeys; |
| 50 | + |
| 51 | + return { [key]: `${values[key]}${unit}` as const }; |
| 52 | + })(), |
| 53 | + ...(() => { |
| 54 | + const key = "sm" satisfies BreakpointKeys; |
| 55 | + |
| 56 | + return { [key]: `${values[key]}${unit}` as const }; |
| 57 | + })(), |
| 58 | + ...(() => { |
| 59 | + const key = "md" satisfies BreakpointKeys; |
| 60 | + |
| 61 | + return { [key]: `${values[key]}${unit}` as const }; |
| 62 | + })(), |
| 63 | + ...(() => { |
| 64 | + const key = "lg" satisfies BreakpointKeys; |
| 65 | + |
| 66 | + return { [key]: `${values[key]}${unit}` as const }; |
| 67 | + })(), |
| 68 | + ...(() => { |
| 69 | + const key = "xl" satisfies BreakpointKeys; |
| 70 | + |
| 71 | + return { [key]: `${values[key]}${unit}` as const }; |
| 72 | + })() |
| 73 | + } as const; |
| 74 | + |
| 75 | + assert<Equals<keyof typeof out, BreakpointKeys>>(); |
| 76 | + |
| 77 | + return out; |
| 78 | + })(), |
| 79 | + "valuesUnit": unit, |
| 80 | + "emValues": (() => { |
| 81 | + assert<Equals<typeof unit, "em">>(); |
| 82 | + |
| 83 | + return values; |
| 84 | + })(), |
46 | 85 | /** |
47 | 86 | * Returns the breakpoint values in px. |
48 | 87 | * |
49 | 88 | * Warning: It reflects the values at a given time, if the root font size changes so will the breakpointsValues. |
50 | 89 | * Plus this function is rather expensive to call. |
51 | 90 | * If you're in react you should use the |
52 | | - * import { useBreakpointsValues } from "@codegouvfr/react-dsfr/useBreakpointsValues"; |
| 91 | + * import { useBreakpointsValuesPx } from "@codegouvfr/react-dsfr/useBreakpointsValuesPx"; |
53 | 92 | */ |
54 | | - "getBreakpointsValues": (): BreakpointsValues => { |
| 93 | + "getPxValues": (): BreakpointsValues => { |
55 | 94 | assert<Equals<typeof unit, "em">>(); |
56 | 95 |
|
57 | 96 | const factor = getBaseFontSizePx(); |
58 | 97 |
|
59 | 98 | return Object.fromEntries( |
60 | 99 | Object.entries(values).map(([key, value]) => [key, value * factor]) |
61 | 100 | ) as any; |
62 | | - } |
| 101 | + }, |
| 102 | + /** @deprecated use breakpoints.values if you're ok with getting the value in em or breakpoints.getPxValues() if you want the value in pixel */ |
| 103 | + "getBreakpointsValues": () => breakpoints.getPxValues() |
63 | 104 | }; |
0 commit comments