import { jsx, jsxs, Fragment } from 'solid-jsx/jsx-runtime';

/*@jsxRuntime automatic @jsxImportSource solid-jsx*/
const toc = [];
function _createMdxContent(props) {
  const _components = Object.assign({
    p: "p",
    code: "code",
    pre: "pre",
    span: "span"
  }, props.components);
  return jsxs(Fragment, {
    children: [jsxs(_components.p, {
      children: ["Solid 支持同时使用 ", jsx(_components.code, {
        children: "class"
      }), " 和 ", jsx(_components.code, {
        children: "className"
      }), " 来设置元素的 ", jsx(_components.code, {
        children: "className"
      }), " 属性。然而，条件设置 class 可以给开发者提供便利。出于这个原因，Solid 提供一个内置的 ", jsx(_components.code, {
        children: "classList"
      }), " JSX 属性，", jsx(_components.code, {
        children: "classList"
      }), " 接受一个对象，其中键是类名，值是一个布尔表达式。当为 true 时应用该 class，当为 false 时该 class 被移除。"]
    }), "\n", jsx(_components.p, {
      children: "我们可以替换："
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: ["<button\n  ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "class"
        }), "={", jsx(_components.span, {
          className: "hljs-title function_",
          children: "current"
        }), "() === ", jsx(_components.span, {
          className: "hljs-string",
          children: "\"foo\""
        }), " ? ", jsx(_components.span, {
          className: "hljs-string",
          children: "\"selected\""
        }), " : ", jsx(_components.span, {
          className: "hljs-string",
          children: "\"\""
        }), "}\n  onClick={", jsx(_components.span, {
          className: "hljs-function",
          children: "() =>"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "setCurrent"
        }), "(", jsx(_components.span, {
          className: "hljs-string",
          children: "\"foo\""
        }), ")}\n>\n  foo\n</button>\n"]
      })
    }), "\n", jsx(_components.p, {
      children: "用下面代码替换:"
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: ["<button\n  classList={{ ", jsx(_components.span, {
          className: "hljs-attr",
          children: "selected"
        }), ": ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "current"
        }), "() === ", jsx(_components.span, {
          className: "hljs-string",
          children: "\"foo\""
        }), " }}\n  onClick={", jsx(_components.span, {
          className: "hljs-function",
          children: "() =>"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "setCurrent"
        }), "(", jsx(_components.span, {
          className: "hljs-string",
          children: "\"foo\""
        }), ")}\n>\n  foo\n</button>\n"]
      })
    }), "\n", jsx(_components.p, {
      children: "也不要忘了，你还可以用 CSS 模块中接收到的类名进行动态设置。"
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "import"
        }), " { active } ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "from"
        }), " ", jsx(_components.span, {
          className: "hljs-string",
          children: "\"./style.module.css\""
        }), ";\n\n", jsx(_components.span, {
          className: "xml",
          children: jsxs(_components.span, {
            className: "hljs-tag",
            children: ["<", jsx(_components.span, {
              className: "hljs-name",
              children: "div"
            }), " ", jsx(_components.span, {
              className: "hljs-attr",
              children: "classList"
            }), "=", jsx(_components.span, {
              className: "hljs-string",
              children: "{{"
            }), " [", jsx(_components.span, {
              className: "hljs-attr",
              children: "active"
            }), "]", jsx(_components.span, {
              className: "hljs-attr",
              children: ":"
            }), " ", jsx(_components.span, {
              className: "hljs-attr",
              children: "isActive"
            }), "() }} />"]
          })
        }), ";\n"]
      })
    })]
  });
}
function MDXContent(props = {}) {
  const {wrapper: MDXLayout} = props.components || ({});
  return MDXLayout ? jsx(MDXLayout, Object.assign({}, props, {
    children: jsx(_createMdxContent, props)
  })) : _createMdxContent(props);
}

export { MDXContent as default, toc };
//# sourceMappingURL=lesson-6bba2dd5.js.map
