All files / src/checktree/_example CheckTreeExample.jsx

75% Statements 3/4
100% Branches 0/0
50% Functions 1/2
75% Lines 3/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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          1x 1x                     1x                                                                                            
import React, { useState } from "react";
import { CheckTree } from "@tencent/tea-component/lib/checktree";
import { Checkbox } from "@tencent/tea-component/lib/checkbox";
 
export default function CheckTreeExample() {
  const [selected, setSelected] = useState(["cc"]);
  const relations = {
    gz: "gd",
    sz: "gd",
    fs: "gd",
    by: "gz",
    th: "gz",
    ns: "sz",
    ft: "sz",
    sd: "fs",
    cc: "fs",
  };
  return (
    <CheckTree
      relations={relations}
      value={selected}
      onChange={value => setSelected(value)}
      disabledNames={["fs"]}
    >
      <Checkbox name="gd">广东省</Checkbox>
      <ul style={{ paddingLeft: 20 }}>
        <li>
          <Checkbox name="gz">广州市</Checkbox>
          <ul style={{ paddingLeft: 20 }}>
            <li>
              <Checkbox name="by">白云区</Checkbox>
            </li>
            <li>
              <Checkbox name="th">天河区</Checkbox>
            </li>
          </ul>
        </li>
        <li>
          <Checkbox name="sz">深圳市</Checkbox>
          <ul style={{ paddingLeft: 20 }}>
            <li>
              <Checkbox name="ns">南山区</Checkbox>
            </li>
            <li>
              <Checkbox name="ft">福田区</Checkbox>
            </li>
          </ul>
        </li>
        <li>
          <Checkbox name="fs">佛山市</Checkbox>
          <ul style={{ paddingLeft: 20 }}>
            <li>
              <Checkbox name="sd">顺德区</Checkbox>
            </li>
            <li>
              <Checkbox name="cc">禅城区</Checkbox>
            </li>
          </ul>
        </li>
      </ul>
    </CheckTree>
  );
}