File size: 2,823 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"use client"

import { Box, Flex, For, Stack, Text, defaultSystem } from "@chakra-ui/react"
import { TokenDoc } from "./token-doc"

const { tokens } = defaultSystem

const allSizes = tokens.categoryMap.get("sizes")!.values()
export const defaultSizes = Array.from(allSizes)

const fractionalSizes = defaultSizes.filter((token) => token.name.includes("/"))
const namedSizes = defaultSizes.filter((token) =>
  token.name.match(/v(h|w)|min|max|fit|prose|full/),
)
const breakpointSizes = defaultSizes.filter((token) =>
  token.name.match(/breakpoint/),
)
const largeSizes = defaultSizes.filter(
  (token) =>
    token.name.match(/sm|xl|xs|lg|md/) && !breakpointSizes.includes(token),
)

const tokenSizes = defaultSizes
  .filter(
    (token) =>
      !fractionalSizes.includes(token) &&
      !namedSizes.includes(token) &&
      !breakpointSizes.includes(token) &&
      !largeSizes.includes(token),
  )
  .sort(
    (a, b) =>
      parseInt(a.extensions.pixelValue!) - parseInt(b.extensions.pixelValue!),
  )

export const SizesTokenDoc = () => {
  return (
    <Stack mt="8" gap="8">
      <For
        each={[
          { name: "tokenSizes", tokens: tokenSizes },
          { name: "namedSizes", tokens: namedSizes },
          { name: "fractionalSizes", tokens: fractionalSizes },
          { name: "breakpointSizes", tokens: breakpointSizes },
          { name: "largeSizes", tokens: largeSizes },
        ]}
      >
        {(item) => (
          <TokenDoc title={item.name}>
            <Flex
              fontSize="sm"
              fontWeight="medium"
              py="1"
              px="3"
              borderBottomWidth="1px"
            >
              <Text width="160px">Name</Text>
              <Text width="100px">Value</Text>
              {item.name === "tokenSizes" && <Text width="100px">Pixel</Text>}
            </Flex>

            <Stack px="3" pt="2">
              {item.tokens.map((token) => (
                <Flex key={token.name} py="1" fontSize="sm">
                  <Text width="160px" fontWeight="medium">
                    {token.extensions.prop}
                  </Text>
                  <Text width="100px" color="fg.muted">
                    {token.value}
                  </Text>
                  {item.name === "tokenSizes" && (
                    <Text width="100px" color="fg.muted">
                      {token.extensions.pixelValue}
                    </Text>
                  )}
                  {item.name === "tokenSizes" && (
                    <Box
                      bg="pink.200"
                      height="4"
                      width={`min(${token.originalValue}, 60%)`}
                    />
                  )}
                </Flex>
              ))}
            </Stack>
          </TokenDoc>
        )}
      </For>
    </Stack>
  )
}