mirror of
https://github.com/wahyd4/ant-design.git
synced 2026-08-27 05:36:20 +10:00
137 lines
46 KiB
HTML
137 lines
46 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="description" content="An enterprise-class UI design language and React-based implementation">
|
|
<meta name="description" content="A set of high-quality React components">
|
|
<meta name="description" content="One of best React UI library for enterprise background">
|
|
<title>Ant Design - A UI Design Language</title>
|
|
<link rel="icon" href="https://t.alipayobjects.com/images/T1QUBfXo4fXXXXXXXX.png" type="image/x-icon">
|
|
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.cnpmjs.org/css?family=Lato:400,700|Raleway"/>
|
|
<link rel="stylesheet" type="text/css" href="/index.css"/>
|
|
<style id="nprogress-style">
|
|
#nprogress { display: none }
|
|
</style>
|
|
<!--[if lte IE 10]>
|
|
<script
|
|
src="https://as.alipayobjects.com/g/component/??console-polyfill/0.2.2/index.js,media-match/2.0.2/media.match.min.js"></script>
|
|
<![endif]-->
|
|
<script>
|
|
if (!window.Intl) {
|
|
document.writeln('<script src="https://as.alipayobjects.com/g/component/intl/1.0.1/??Intl.js,locale-data/jsonp/en.js,locale-data/jsonp/zh.js">' + '<' + '/script>');
|
|
}
|
|
if (!window.Promise) {
|
|
document.writeln('<script src="https://as.alipayobjects.com/g/component/es6-promise/3.2.2/es6-promise.min.js"' + '>' + '<' + '/' + 'script>');
|
|
}
|
|
</script>
|
|
<script>
|
|
// Enable Google Analytics
|
|
if (!location.port) {
|
|
/* eslint-disable */
|
|
(function (i, s, o, g, r, a, m) {
|
|
i['GoogleAnalyticsObject'] = r;
|
|
i[r] = i[r] || function () {
|
|
(i[r].q = i[r].q || []).push(arguments)
|
|
}, i[r].l = 1 * new Date();
|
|
a = s.createElement(o),
|
|
m = s.getElementsByTagName(o)[0];
|
|
a.async = 1;
|
|
a.src = g;
|
|
m.parentNode.insertBefore(a, m)
|
|
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
|
|
ga('create', 'UA-72788897-1', 'auto');
|
|
ga('send', 'pageview');
|
|
/* eslint-enable */
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="react-content">
|
|
<div class="page-wrapper" data-reactroot="" data-reactid="1" data-react-checksum="-2080229021"><header id="header" class="clearfix" data-reactid="2"><div class="ant-row" data-reactid="3"><div class="ant-col-xs-24 ant-col-sm-24 ant-col-md-6 ant-col-lg-4" data-reactid="4"><a id="logo" href="/" data-reactid="5"><img alt="logo" src="https://t.alipayobjects.com/images/rmsweb/T1B9hfXcdvXXXXXXXX.svg" data-reactid="6"/><span data-reactid="7">Ant Design</span></a></div><div class="ant-col-xs-0 ant-col-sm-0 ant-col-md-18 ant-col-lg-20" data-reactid="8"><div id="search-box" data-reactid="9"><div class="ant-select ant-select-combobox ant-select-enabled" data-reactid="10"><div class="ant-select-selection
|
|
ant-select-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" data-reactid="11"><div class="ant-select-selection__rendered" data-reactid="12"><div style="display:block;user-select:none;-webkit-user-select:none;" unselectable="unselectable" class="ant-select-selection__placeholder" data-reactid="13">Search Components...</div><ul data-reactid="14"><li class="ant-select-search ant-select-search--inline" data-reactid="15"><div class="ant-select-search__field__wrap" data-reactid="16"><input value="" class="ant-select-search__field" data-reactid="17"/><span class="ant-select-search__field__mirror" data-reactid="18"></span></div></li></ul></div><span class="ant-select-arrow" style="user-select:none;-webkit-user-select:none;" unselectable="unselectable" data-reactid="19"><b data-reactid="20"></b></span></div></div></div><button type="button" class="ant-btn ant-btn-ghost ant-btn-sm lang" data-reactid="21"><span data-reactid="22">中文</span></button><ul class="ant-menu ant-menu-horizontal ant-menu-light ant-menu-root" role="menu" aria-activedescendant="" id="nav" tabindex="0" data-reactid="23"><li class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="24"><a href="/" data-reactid="25"><span data-reactid="26">Home</span></a></li><li class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="27"><a href="/docs/spec/introduce" data-reactid="28"><span data-reactid="29">Specification</span></a></li><li class="ant-menu-item-selected ant-menu-item" role="menuitem" aria-selected="true" data-reactid="30"><a href="/docs/react/introduce" data-reactid="31"><span data-reactid="32">Components</span></a></li><li class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="33"><a href="/docs/pattern/navigation" data-reactid="34"><span data-reactid="35">Pattern</span></a></li><li class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="36"><a href="/docs/practice/cases" data-reactid="37"><span data-reactid="38">Practice</span></a></li><li class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="39"><a href="/docs/resource/download" data-reactid="40"><span data-reactid="41">Resource</span></a></li></ul></div></div></header><div class="main-wrapper" data-reactid="42"><div class="ant-row" data-reactid="43"><div class="ant-col-xs-24 ant-col-sm-24 ant-col-md-6 ant-col-lg-4" data-reactid="44"><ul class="ant-menu ant-menu-inline aside-container ant-menu-light ant-menu-root" role="menu" aria-activedescendant="" tabindex="0" data-reactid="45"><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="46"><a href="/docs/react/introduce" data-reactid="47">Ant Design of React</a></li><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="48"><a href="/docs/react/getting-started" data-reactid="49">Getting Started</a></li><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="50"><a href="/docs/react/practical-projects" data-reactid="51">Real project with dva</a></li><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="52"><a href="/docs/react/use-with-create-react-app" data-reactid="53">Use in create-react-app</a></li><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="54"><a href="/docs/react/customize-theme" data-reactid="55">Customize Theme</a></li><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="56"><a href="/changelog" data-reactid="57">Change Log</a></li><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="58"><a href="/docs/react/recommendation" data-reactid="59">Third-Party Library</a></li><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="60"><a href="https://github.com/websemantics/awesome-ant-design" target="_blank" rel="noopener noreferrer" class="menu-item-link-outside" data-reactid="61"><!-- react-text: 62 -->Awesome Ant Design<!-- /react-text --><!-- react-text: 63 --> <!-- /react-text --><i class="anticon anticon-export" data-reactid="64"></i></a></li><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="65"><a href="//github.com/ant-design/intl-example" target="_blank" rel="noopener noreferrer" class="menu-item-link-outside" data-reactid="66"><!-- react-text: 67 -->i18n Solution<!-- /react-text --><!-- react-text: 68 --> <!-- /react-text --><i class="anticon anticon-export" data-reactid="69"></i></a></li><li class="ant-menu-submenu-inline ant-menu-submenu-open ant-menu-submenu-selected ant-menu-submenu" data-reactid="70"><div style="padding-left:24px;" class="ant-menu-submenu-title" aria-expanded="true" aria-owns="Components$Menu" aria-haspopup="true" data-reactid="71"><h4 data-reactid="72">Components</h4></div><ul class="ant-menu ant-menu-inline ant-menu-sub" role="menu" aria-activedescendant="" id="Components$Menu" data-reactid="73"><li class=" ant-menu-item-group" data-reactid="74"><div class="ant-menu-item-group-title" data-reactid="75">General</div><ul class="ant-menu-item-group-list" data-reactid="76"><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="77"><a href="/components/button/" data-reactid="78"><span data-reactid="79">Button</span><span class="chinese" data-reactid="80"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="81"><a href="/components/icon/" data-reactid="82"><span data-reactid="83">Icon</span><span class="chinese" data-reactid="84"></span></a></li></ul></li><li class=" ant-menu-item-group" data-reactid="85"><div class="ant-menu-item-group-title" data-reactid="86">Layout</div><ul class="ant-menu-item-group-list" data-reactid="87"><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="88"><a href="/components/grid/" data-reactid="89"><span data-reactid="90">Grid</span><span class="chinese" data-reactid="91"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="92"><a href="/components/layout/" data-reactid="93"><span data-reactid="94">Layout</span><span class="chinese" data-reactid="95"></span></a></li></ul></li><li class=" ant-menu-item-group" data-reactid="96"><div class="ant-menu-item-group-title" data-reactid="97">Navigation</div><ul class="ant-menu-item-group-list" data-reactid="98"><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="99"><a href="/components/affix/" data-reactid="100"><span data-reactid="101">Affix</span><span class="chinese" data-reactid="102"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="103"><a href="/components/back-top/" data-reactid="104"><span data-reactid="105">BackTop</span><span class="chinese" data-reactid="106"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="107"><a href="/components/breadcrumb/" data-reactid="108"><span data-reactid="109">Breadcrumb</span><span class="chinese" data-reactid="110"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="111"><a href="/components/dropdown/" data-reactid="112"><span data-reactid="113">Dropdown</span><span class="chinese" data-reactid="114"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="115"><a href="/components/menu/" data-reactid="116"><span data-reactid="117">Menu</span><span class="chinese" data-reactid="118"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="119"><a href="/components/pagination/" data-reactid="120"><span data-reactid="121">Pagination</span><span class="chinese" data-reactid="122"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="123"><a href="/components/steps/" data-reactid="124"><span data-reactid="125">Steps</span><span class="chinese" data-reactid="126"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="127"><a href="/components/tabs/" data-reactid="128"><span data-reactid="129">Tabs</span><span class="chinese" data-reactid="130"></span></a></li></ul></li><li class=" ant-menu-item-group" data-reactid="131"><div class="ant-menu-item-group-title" data-reactid="132">Data Entry</div><ul class="ant-menu-item-group-list" data-reactid="133"><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="134"><a href="/components/auto-complete/" data-reactid="135"><span data-reactid="136">AutoComplete</span><span class="chinese" data-reactid="137"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="138"><a href="/components/checkbox/" data-reactid="139"><span data-reactid="140">Checkbox</span><span class="chinese" data-reactid="141"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="142"><a href="/components/cascader/" data-reactid="143"><span data-reactid="144">Cascader</span><span class="chinese" data-reactid="145"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="146"><a href="/components/date-picker/" data-reactid="147"><span data-reactid="148">DatePicker</span><span class="chinese" data-reactid="149"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="150"><a href="/components/form/" data-reactid="151"><span data-reactid="152">Form</span><span class="chinese" data-reactid="153"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="154"><a href="/components/input/" data-reactid="155"><span data-reactid="156">Input</span><span class="chinese" data-reactid="157"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="158"><a href="/components/input-number/" data-reactid="159"><span data-reactid="160">InputNumber</span><span class="chinese" data-reactid="161"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="162"><a href="/components/mention/" data-reactid="163"><span data-reactid="164">Mention</span><span class="chinese" data-reactid="165"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="166"><a href="/components/radio/" data-reactid="167"><span data-reactid="168">Radio</span><span class="chinese" data-reactid="169"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="170"><a href="/components/rate/" data-reactid="171"><span data-reactid="172">Rate</span><span class="chinese" data-reactid="173"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="174"><a href="/components/select/" data-reactid="175"><span data-reactid="176">Select</span><span class="chinese" data-reactid="177"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="178"><a href="/components/slider/" data-reactid="179"><span data-reactid="180">Slider</span><span class="chinese" data-reactid="181"></span></a></li><li style="padding-left:48px;" class="ant-menu-item-selected ant-menu-item" role="menuitem" aria-selected="true" data-reactid="182"><a href="/components/switch/" data-reactid="183"><span data-reactid="184">Switch</span><span class="chinese" data-reactid="185"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="186"><a href="/components/time-picker/" data-reactid="187"><span data-reactid="188">TimePicker</span><span class="chinese" data-reactid="189"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="190"><a href="/components/transfer/" data-reactid="191"><span data-reactid="192">Transfer</span><span class="chinese" data-reactid="193"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="194"><a href="/components/tree-select/" data-reactid="195"><span data-reactid="196">TreeSelect</span><span class="chinese" data-reactid="197"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="198"><a href="/components/upload/" data-reactid="199"><span data-reactid="200">Upload</span><span class="chinese" data-reactid="201"></span></a></li></ul></li><li class=" ant-menu-item-group" data-reactid="202"><div class="ant-menu-item-group-title" data-reactid="203">Data Display</div><ul class="ant-menu-item-group-list" data-reactid="204"><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="205"><a href="/components/badge/" data-reactid="206"><span data-reactid="207">Badge</span><span class="chinese" data-reactid="208"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="209"><a href="/components/card/" data-reactid="210"><span data-reactid="211">Card</span><span class="chinese" data-reactid="212"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="213"><a href="/components/carousel/" data-reactid="214"><span data-reactid="215">Carousel</span><span class="chinese" data-reactid="216"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="217"><a href="/components/collapse/" data-reactid="218"><span data-reactid="219">Collapse</span><span class="chinese" data-reactid="220"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="221"><a href="/components/calendar/" data-reactid="222"><span data-reactid="223">Calendar</span><span class="chinese" data-reactid="224"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="225"><a href="/components/popover/" data-reactid="226"><span data-reactid="227">Popover</span><span class="chinese" data-reactid="228"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="229"><a href="/components/table/" data-reactid="230"><span data-reactid="231">Table</span><span class="chinese" data-reactid="232"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="233"><a href="/components/tag/" data-reactid="234"><span data-reactid="235">Tag</span><span class="chinese" data-reactid="236"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="237"><a href="/components/timeline/" data-reactid="238"><span data-reactid="239">Timeline</span><span class="chinese" data-reactid="240"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="241"><a href="/components/tooltip/" data-reactid="242"><span data-reactid="243">Tooltip</span><span class="chinese" data-reactid="244"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="245"><a href="/components/tree/" data-reactid="246"><span data-reactid="247">Tree</span><span class="chinese" data-reactid="248"></span></a></li></ul></li><li class=" ant-menu-item-group" data-reactid="249"><div class="ant-menu-item-group-title" data-reactid="250">Feedback</div><ul class="ant-menu-item-group-list" data-reactid="251"><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="252"><a href="/components/alert/" data-reactid="253"><span data-reactid="254">Alert</span><span class="chinese" data-reactid="255"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="256"><a href="/components/message/" data-reactid="257"><span data-reactid="258">Message</span><span class="chinese" data-reactid="259"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="260"><a href="/components/modal/" data-reactid="261"><span data-reactid="262">Modal</span><span class="chinese" data-reactid="263"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="264"><a href="/components/notification/" data-reactid="265"><span data-reactid="266">Notification</span><span class="chinese" data-reactid="267"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="268"><a href="/components/popconfirm/" data-reactid="269"><span data-reactid="270">Popconfirm</span><span class="chinese" data-reactid="271"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="272"><a href="/components/progress/" data-reactid="273"><span data-reactid="274">Progress</span><span class="chinese" data-reactid="275"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="276"><a href="/components/spin/" data-reactid="277"><span data-reactid="278">Spin</span><span class="chinese" data-reactid="279"></span></a></li></ul></li><li class=" ant-menu-item-group" data-reactid="280"><div class="ant-menu-item-group-title" data-reactid="281">Other</div><ul class="ant-menu-item-group-list" data-reactid="282"><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="283"><a href="/components/anchor/" data-reactid="284"><span data-reactid="285">Anchor</span><span class="chinese" data-reactid="286"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="287"><a href="/components/locale-provider/" data-reactid="288"><span data-reactid="289">LocaleProvider</span><span class="chinese" data-reactid="290"></span></a></li></ul></li></ul></li></ul></div><div class="main-container ant-col-xs-24 ant-col-sm-24 ant-col-md-18 ant-col-lg-20" data-reactid="291"><article data-reactid="292"><div class="toc-affix" data-reactid="293"><div class="" data-reactid="294"><ul class="toc demos-anchor" data-reactid="295"><li title="Basic" data-reactid="296"><a href="#components-switch-demo-basic" data-reactid="297">Basic</a></li><li title="Disabled" data-reactid="298"><a href="#components-switch-demo-disabled" data-reactid="299">Disabled</a></li><li title="Text & icon" data-reactid="300"><a href="#components-switch-demo-text" data-reactid="301">Text & icon</a></li><li title="Two sizes" data-reactid="302"><a href="#components-switch-demo-size" data-reactid="303">Two sizes</a></li></ul></div></div><section class="markdown" data-reactid="304"><h1 data-reactid="305"><!-- react-text: 306 -->Switch<!-- /react-text --><a class="edit-button" href="https://github.com/ant-design/ant-design/blob/master/components/switch/index.en-US.md" data-reactid="307"><i class="anticon anticon-edit" data-reactid="308"></i></a></h1><section class="markdown" data-reactid="309"><p data-reactid="310"><!-- react-text: 311 -->Switching Selector.<!-- /react-text --></p><h2 id="When-To-Use" data-reactid="312"><span data-reactid="313"><!-- react-text: 314 -->When To Use<!-- /react-text --></span><a href="#When-To-Use" class="anchor" data-reactid="315">#</a></h2><ul data-reactid="316"><li data-reactid="317"><p data-reactid="318"><!-- react-text: 319 -->If you need to represent the switching between two states or on-off state.<!-- /react-text --></p></li><li data-reactid="320"><p data-reactid="321"><!-- react-text: 322 -->The difference between <!-- /react-text --><code data-reactid="323"><!-- react-text: 324 -->Switch<!-- /react-text --></code><!-- react-text: 325 --> and <!-- /react-text --><code data-reactid="326"><!-- react-text: 327 -->Checkbox<!-- /react-text --></code><!-- react-text: 328 --> is that <!-- /react-text --><code data-reactid="329"><!-- react-text: 330 -->Switch<!-- /react-text --></code><!-- react-text: 331 --> will trigger a state change directly when you toggle it, while <!-- /react-text --><code data-reactid="332"><!-- react-text: 333 -->Checkbox<!-- /react-text --></code><!-- react-text: 334 --> is generally used for state marking, which should work in conjunction with submit operation.<!-- /react-text --></p></li></ul></section><h2 data-reactid="335"><span data-reactid="336">Examples</span><i class="anticon anticon-appstore code-box-expand-trigger" title="展开全部代码" data-reactid="337"></i></h2></section><div class="ant-row" style="margin-left:-8px;margin-right:-8px;" data-reactid="338"><div style="padding-left:8px;padding-right:8px;" class="ant-col-12 code-boxes-col-2-1" data-reactid="339"><section class="code-box" id="components-switch-demo-basic" data-reactid="340"><section class="code-box-demo" data-reactid="341"><span class="ant-switch" tabindex="0" data-reactid="342"><span class="ant-switch-inner" data-reactid="343"></span></span><style data-reactid="344">
|
|
.ant-switch {
|
|
margin-bottom: 8px;
|
|
}
|
|
<style></style></section><section class="code-box-meta markdown" data-reactid="345"><div class="code-box-title" data-reactid="346"><a href="#components-switch-demo-basic" data-reactid="347">Basic</a><a class="edit-button" href="https://github.com/ant-design/ant-design/blob/master/components/switch/demo/basic.md" data-reactid="348"><i class="anticon anticon-edit" data-reactid="349"></i></a></div><div data-reactid="350"><p data-reactid="351"><!-- react-text: 352 -->The most basic usage.<!-- /react-text --></p></div><i title="Show Code" class="anticon anticon-down-circle-o collapse" data-reactid="353"></i></section><section class="highlight-wrapper" data-reactid="354"><div class="highlight" data-reactid="355"><pre class="language-__react" data-reactid="356"><code data-reactid="357">import { <span class="token keyword">Switch</span> } from <span class="token string">'antd'</span><span class="token comment" spellcheck="true">;</span>
|
|
|
|
function <span class="token function">onChange</span><span class="token punctuation">(</span>checked<span class="token punctuation">)</span> {
|
|
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>`<span class="token keyword">switch</span> <span class="token keyword">to</span> ${checked}`<span class="token punctuation">)</span><span class="token comment" spellcheck="true">;</span>
|
|
}
|
|
|
|
ReactDOM<span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span>
|
|
<span class="token operator"><</span><span class="token keyword">Switch</span> defaultChecked<span class="token operator">=</span>{<span class="token boolean">false</span>} onChange<span class="token operator">=</span>{onChange} <span class="token operator">/</span><span class="token operator">></span><span class="token punctuation">,</span>
|
|
mountNode
|
|
<span class="token punctuation">)</span><span class="token comment" spellcheck="true">;</span></code></pre></div></section></section><section class="code-box" id="components-switch-demo-text" data-reactid="358"><section class="code-box-demo" data-reactid="359"><div data-reactid="360"><span class="ant-switch" tabindex="0" data-reactid="361"><span class="ant-switch-inner" data-reactid="362">关</span></span><br data-reactid="363"/><span class="ant-switch" tabindex="0" data-reactid="364"><span class="ant-switch-inner" data-reactid="365">0</span></span><br data-reactid="366"/><span class="ant-switch" tabindex="0" data-reactid="367"><span class="ant-switch-inner" data-reactid="368"><i class="anticon anticon-cross" data-reactid="369"></i></span></span></div></section><section class="code-box-meta markdown" data-reactid="370"><div class="code-box-title" data-reactid="371"><a href="#components-switch-demo-text" data-reactid="372">Text & icon</a><a class="edit-button" href="https://github.com/ant-design/ant-design/blob/master/components/switch/demo/text.md" data-reactid="373"><i class="anticon anticon-edit" data-reactid="374"></i></a></div><div data-reactid="375"><p data-reactid="376"><!-- react-text: 377 -->With text and icon.<!-- /react-text --></p></div><i title="Show Code" class="anticon anticon-down-circle-o collapse" data-reactid="378"></i></section><section class="highlight-wrapper" data-reactid="379"><div class="highlight" data-reactid="380"><pre class="language-__react" data-reactid="381"><code data-reactid="382">import { <span class="token keyword">Switch</span><span class="token punctuation">,</span> Icon } from <span class="token string">'antd'</span><span class="token comment" spellcheck="true">;</span>
|
|
|
|
ReactDOM<span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span><span class="token operator"><</span>div<span class="token operator">></span>
|
|
<span class="token operator"><</span><span class="token keyword">Switch</span> checkedChildren<span class="token operator">=</span>{<span class="token string">'开'</span>} unCheckedChildren<span class="token operator">=</span>{<span class="token string">'关'</span>} <span class="token operator">/</span><span class="token operator">></span>
|
|
<span class="token operator"><</span>br <span class="token operator">/</span><span class="token operator">></span>
|
|
<span class="token operator"><</span><span class="token keyword">Switch</span> checkedChildren<span class="token operator">=</span><span class="token string">"1"</span> unCheckedChildren<span class="token operator">=</span><span class="token string">"0"</span> <span class="token operator">/</span><span class="token operator">></span>
|
|
<span class="token operator"><</span>br <span class="token operator">/</span><span class="token operator">></span>
|
|
<span class="token operator"><</span><span class="token keyword">Switch</span> checkedChildren<span class="token operator">=</span>{<span class="token operator"><</span>Icon type<span class="token operator">=</span><span class="token string">"check"</span> <span class="token operator">/</span><span class="token operator">></span>} unCheckedChildren<span class="token operator">=</span>{<span class="token operator"><</span>Icon type<span class="token operator">=</span><span class="token string">"cross"</span> <span class="token operator">/</span><span class="token operator">></span>} <span class="token operator">/</span><span class="token operator">></span>
|
|
<span class="token operator"><</span><span class="token operator">/</span>div<span class="token operator">></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token comment" spellcheck="true">;</span></code></pre></div></section></section></div><div style="padding-left:8px;padding-right:8px;" class="ant-col-12 code-boxes-col-2-1" data-reactid="383"><section class="code-box" id="components-switch-demo-disabled" data-reactid="384"><section class="code-box-demo" data-reactid="385"><div data-reactid="386"><span class="ant-switch ant-switch-disabled" tabindex="0" data-reactid="387"><span class="ant-switch-inner" data-reactid="388"></span></span><br data-reactid="389"/><button type="button" class="ant-btn ant-btn-primary" data-reactid="390"><span data-reactid="391">Toggle disabled</span></button></div></section><section class="code-box-meta markdown" data-reactid="392"><div class="code-box-title" data-reactid="393"><a href="#components-switch-demo-disabled" data-reactid="394">Disabled</a><a class="edit-button" href="https://github.com/ant-design/ant-design/blob/master/components/switch/demo/disabled.md" data-reactid="395"><i class="anticon anticon-edit" data-reactid="396"></i></a></div><div data-reactid="397"><p data-reactid="398"><!-- react-text: 399 -->Disabled state of <!-- /react-text --><code data-reactid="400"><!-- react-text: 401 -->Switch<!-- /react-text --></code><!-- react-text: 402 -->.<!-- /react-text --></p></div><i title="Show Code" class="anticon anticon-down-circle-o collapse" data-reactid="403"></i></section><section class="highlight-wrapper" data-reactid="404"><div class="highlight" data-reactid="405"><pre class="language-__react" data-reactid="406"><code data-reactid="407">import { <span class="token keyword">Switch</span><span class="token punctuation">,</span> Button } from <span class="token string">'antd'</span><span class="token comment" spellcheck="true">;</span>
|
|
|
|
<span class="token keyword">const</span> Test <span class="token operator">=</span> React<span class="token punctuation">.</span><span class="token function">createClass</span><span class="token punctuation">(</span>{
|
|
<span class="token function">getInitialState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> {
|
|
return {
|
|
disabled<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
|
|
}<span class="token comment" spellcheck="true">;</span>
|
|
}<span class="token punctuation">,</span>
|
|
<span class="token function">toggle</span><span class="token punctuation">(</span><span class="token punctuation">)</span> {
|
|
this<span class="token punctuation">.</span><span class="token function">setState</span><span class="token punctuation">(</span>{
|
|
disabled<span class="token punctuation">:</span> !this<span class="token punctuation">.</span>state<span class="token punctuation">.</span>disabled<span class="token punctuation">,</span>
|
|
}<span class="token punctuation">)</span><span class="token comment" spellcheck="true">;</span>
|
|
}<span class="token punctuation">,</span>
|
|
<span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> {
|
|
return <span class="token punctuation">(</span>
|
|
<span class="token operator"><</span>div<span class="token operator">></span>
|
|
<span class="token operator"><</span><span class="token keyword">Switch</span> disabled<span class="token operator">=</span>{this<span class="token punctuation">.</span>state<span class="token punctuation">.</span>disabled} <span class="token operator">/</span><span class="token operator">></span>
|
|
<span class="token operator"><</span>br <span class="token operator">/</span><span class="token operator">></span>
|
|
<span class="token operator"><</span>Button type<span class="token operator">=</span><span class="token string">"primary"</span> onClick<span class="token operator">=</span>{this<span class="token punctuation">.</span>toggle}<span class="token operator">></span>Toggle disabled<span class="token operator"><</span><span class="token operator">/</span>Button<span class="token operator">></span>
|
|
<span class="token operator"><</span><span class="token operator">/</span>div<span class="token operator">></span>
|
|
<span class="token punctuation">)</span><span class="token comment" spellcheck="true">;</span>
|
|
}<span class="token punctuation">,</span>
|
|
}<span class="token punctuation">)</span><span class="token comment" spellcheck="true">;</span>
|
|
|
|
ReactDOM<span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span><span class="token operator"><</span>Test <span class="token operator">/</span><span class="token operator">></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token comment" spellcheck="true">;</span></code></pre></div></section></section><section class="code-box" id="components-switch-demo-size" data-reactid="408"><section class="code-box-demo" data-reactid="409"><div data-reactid="410"><span class="ant-switch" tabindex="0" data-reactid="411"><span class="ant-switch-inner" data-reactid="412"></span></span><br data-reactid="413"/><span class="ant-switch-small ant-switch" tabindex="0" data-reactid="414"><span class="ant-switch-inner" data-reactid="415"></span></span></div></section><section class="code-box-meta markdown" data-reactid="416"><div class="code-box-title" data-reactid="417"><a href="#components-switch-demo-size" data-reactid="418">Two sizes</a><a class="edit-button" href="https://github.com/ant-design/ant-design/blob/master/components/switch/demo/size.md" data-reactid="419"><i class="anticon anticon-edit" data-reactid="420"></i></a></div><div data-reactid="421"><p data-reactid="422"><code data-reactid="423"><!-- react-text: 424 -->size="small"<!-- /react-text --></code><!-- react-text: 425 --> represents a small sized switch.<!-- /react-text --></p></div><i title="Show Code" class="anticon anticon-down-circle-o collapse" data-reactid="426"></i></section><section class="highlight-wrapper" data-reactid="427"><div class="highlight" data-reactid="428"><pre class="language-__react" data-reactid="429"><code data-reactid="430">import { <span class="token keyword">Switch</span> } from <span class="token string">'antd'</span><span class="token comment" spellcheck="true">;</span>
|
|
|
|
ReactDOM<span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span>
|
|
<span class="token operator"><</span>div<span class="token operator">></span>
|
|
<span class="token operator"><</span><span class="token keyword">Switch</span> <span class="token operator">/</span><span class="token operator">></span>
|
|
<span class="token operator"><</span>br <span class="token operator">/</span><span class="token operator">></span>
|
|
<span class="token operator"><</span><span class="token keyword">Switch</span> size<span class="token operator">=</span><span class="token string">"small"</span> <span class="token operator">/</span><span class="token operator">></span>
|
|
<span class="token operator"><</span><span class="token operator">/</span>div<span class="token operator">></span>
|
|
<span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token comment" spellcheck="true">;</span></code></pre></div></section></section></div></div><section class="markdown api-container" data-reactid="431"><h2 id="API" data-reactid="432"><span data-reactid="433"><!-- react-text: 434 -->API<!-- /react-text --></span><a href="#API" class="anchor" data-reactid="435">#</a></h2><h3 id="Switch" data-reactid="436"><span data-reactid="437"><!-- react-text: 438 -->Switch<!-- /react-text --></span><a href="#Switch" class="anchor" data-reactid="439">#</a></h3><table data-reactid="440"><thead data-reactid="441"><tr data-reactid="442"><th data-reactid="443"><!-- react-text: 444 -->Property<!-- /react-text --></th><th data-reactid="445"><!-- react-text: 446 -->Description<!-- /react-text --></th><th data-reactid="447"><!-- react-text: 448 -->Type<!-- /react-text --></th><th data-reactid="449"><!-- react-text: 450 -->Default<!-- /react-text --></th></tr></thead><tbody data-reactid="451"><tr data-reactid="452"><td data-reactid="453"><!-- react-text: 454 -->checked<!-- /react-text --></td><td data-reactid="455"><!-- react-text: 456 -->determine whether the <!-- /react-text --><code data-reactid="457"><!-- react-text: 458 -->Switch<!-- /react-text --></code><!-- react-text: 459 --> is checked<!-- /react-text --></td><td data-reactid="460"><!-- react-text: 461 -->boolean<!-- /react-text --></td><td data-reactid="462"><!-- react-text: 463 -->false<!-- /react-text --></td></tr><tr data-reactid="464"><td data-reactid="465"><!-- react-text: 466 -->defaultChecked<!-- /react-text --></td><td data-reactid="467"><!-- react-text: 468 -->to set the initial state<!-- /react-text --></td><td data-reactid="469"><!-- react-text: 470 -->boolean<!-- /react-text --></td><td data-reactid="471"><!-- react-text: 472 -->false<!-- /react-text --></td></tr><tr data-reactid="473"><td data-reactid="474"><!-- react-text: 475 -->onChange<!-- /react-text --></td><td data-reactid="476"><!-- react-text: 477 -->a callback function, can be executed when the checked state is changing<!-- /react-text --></td><td data-reactid="478"><!-- react-text: 479 -->Function(checked:Boolean)<!-- /react-text --></td><td data-reactid="480"></td></tr><tr data-reactid="481"><td data-reactid="482"><!-- react-text: 483 -->checkedChildren<!-- /react-text --></td><td data-reactid="484"><!-- react-text: 485 -->content to be shown when the state is checked<!-- /react-text --></td><td data-reactid="486"><!-- react-text: 487 -->string<!-- /react-text --><!-- react-text: 488 -->|<!-- /react-text --><!-- react-text: 489 -->ReactNode<!-- /react-text --></td><td data-reactid="490"></td></tr><tr data-reactid="491"><td data-reactid="492"><!-- react-text: 493 -->unCheckedChildren<!-- /react-text --></td><td data-reactid="494"><!-- react-text: 495 -->content to be shown when the state is unchecked<!-- /react-text --></td><td data-reactid="496"><!-- react-text: 497 -->string<!-- /react-text --><!-- react-text: 498 -->|<!-- /react-text --><!-- react-text: 499 -->ReactNode<!-- /react-text --></td><td data-reactid="500"></td></tr><tr data-reactid="501"><td data-reactid="502"><!-- react-text: 503 -->size<!-- /react-text --></td><td data-reactid="504"><!-- react-text: 505 -->the size of the <!-- /react-text --><code data-reactid="506"><!-- react-text: 507 -->Switch<!-- /react-text --></code><!-- react-text: 508 -->, options: <!-- /react-text --><code data-reactid="509"><!-- react-text: 510 -->default<!-- /react-text --></code><!-- react-text: 511 --> <!-- /react-text --><code data-reactid="512"><!-- react-text: 513 -->small<!-- /react-text --></code></td><td data-reactid="514"><!-- react-text: 515 -->string<!-- /react-text --></td><td data-reactid="516"><!-- react-text: 517 -->default<!-- /react-text --></td></tr></tbody></table></section></article></div></div><div class="ant-row" data-reactid="518"><div class="ant-col-xs-24 ant-col-sm-24 ant-col-md-18 ant-col-md-offset-6 ant-col-lg-20 ant-col-lg-offset-4" data-reactid="519"><section class="prev-next-nav" data-reactid="520"><a class="prev-page" href="/components/slider/" data-reactid="521"><span data-reactid="522">Slider</span><span class="chinese" data-reactid="523"></span></a><a class="next-page" href="/components/time-picker/" data-reactid="524"><span data-reactid="525">TimePicker</span><span class="chinese" data-reactid="526"></span></a></section></div></div></div><footer id="footer" data-reactid="527"><ul data-reactid="528"><li data-reactid="529"><h2 data-reactid="530">GitHub</h2><div data-reactid="531"><a target="_blank " href="https://github.com/ant-design/ant-design" data-reactid="532"><span data-reactid="533">Repository</span></a></div><div data-reactid="534"><a target="_blank" rel="noopener noreferrer" href="https://github.com/dvajs/dva" data-reactid="535">dva</a><!-- react-text: 536 --> - <!-- /react-text --><span data-reactid="537">Framework</span></div><div data-reactid="538"><a target="_blank" rel="noopener noreferrer" href="https://github.com/dvajs/dva-cli" data-reactid="539">dva-cli</a><!-- react-text: 540 --> -<!-- /react-text --><span data-reactid="541">Scaffold</span></div><div data-reactid="542"><a target="_blank" rel="noopener noreferrer" href="http://ant-tool.github.io" data-reactid="543">ant-tool</a><!-- react-text: 544 --> - <!-- /react-text --><span data-reactid="545">Developer Tools</span></div></li><li data-reactid="546"><h2 data-reactid="547"><span data-reactid="548">Links</span></h2><div data-reactid="549"><a href="http://mobile.ant.design" data-reactid="550">Ant Design Mobile</a><span data-reactid="551"> - </span><span data-reactid="552">Mobile</span></div><div data-reactid="553"><a href="https://g2.alipay.com/" data-reactid="554">G2</a><span data-reactid="555"> - </span><span data-reactid="556">Data Visualization</span></div><div data-reactid="557"><a href="https://antv.alipay.com/" data-reactid="558">AntV</a><span data-reactid="559"> - </span><span data-reactid="560">Data Visualization Specification</span></div><div data-reactid="561"><a href="http://motion.ant.design" data-reactid="562">Ant Motion</a><span data-reactid="563"> - </span><span data-reactid="564">Motion</span></div><div data-reactid="565"><a href="http://library.ant.design/" data-reactid="566">AntD Library</a><span data-reactid="567"> - </span><span data-reactid="568">Axure library of Ant Design</span></div><div data-reactid="569"><a href="http://ux.ant.design" data-reactid="570">Ant UX</a><span data-reactid="571"> - </span><span data-reactid="572">Sitemap Template</span></div></li><li data-reactid="573"><h2 data-reactid="574"><span data-reactid="575">Community</span></h2><div data-reactid="576"><a rel="noopener noreferrer" href="/changelog" data-reactid="577"><span data-reactid="578">Change Log</span></a></div><div data-reactid="579"><a target="_blank" rel="noopener noreferrer" href="https://github.com/ant-design/ant-design/issues" data-reactid="580"><span data-reactid="581">Feedback</span></a></div><div data-reactid="582"><a target="_blank" rel="noopener noreferrer" href="https://gitter.im/ant-design/ant-design" data-reactid="583"><span data-reactid="584">Chat Room</span></a></div><div data-reactid="585"><a target="_blank" rel="noopener noreferrer" href="https://github.com/ant-design/ant-design/issues/new" data-reactid="586"><span data-reactid="587">Bug Report</span></a></div></li><li data-reactid="588"><div data-reactid="589"><!-- react-text: 590 -->©2016 <!-- /react-text --><span data-reactid="591">Created by Ant UED</span></div><div data-reactid="592"><!-- react-text: 593 -->Powered by <!-- /react-text --><a href="https://github.com/benjycui/bisheng" data-reactid="594">BiSheng</a></div><div style="margin-top:10px;" data-reactid="595"><span data-reactid="596">Version: </span><div class="ant-select-sm ant-select ant-select-enabled" data-reactid="597"><div class="ant-select-selection
|
|
ant-select-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" tabindex="0" data-reactid="598"><div class="ant-select-selection__rendered" data-reactid="599"><div class="ant-select-selection-selected-value" title="2.6.4" style="display:block;opacity:1;" data-reactid="600">2.6.4</div></div><span class="ant-select-arrow" style="user-select:none;-webkit-user-select:none;" unselectable="unselectable" data-reactid="601"><b data-reactid="602"></b></span></div></div></div></li></ul></footer></div>
|
|
</div>
|
|
<script>
|
|
function isZhCN(pathname) {
|
|
return /-cn\/?$/.test(pathname);
|
|
}
|
|
function getLocalizedPathname(path, zhCN) {
|
|
var pathname = path.startsWith('/') ? path : '/' + path;
|
|
if (!zhCN) { // to enUS
|
|
return /\/?index-cn/.test(pathname) ? '/' : pathname.replace('-cn', '');
|
|
} else if (pathname === '/') {
|
|
return '/index-cn';
|
|
} else if (pathname.endsWith('/')) {
|
|
return pathname.replace(/\/$/, '-cn/');
|
|
}
|
|
return pathname + '-cn';
|
|
}
|
|
var queryString = location.search;
|
|
if (queryString) {
|
|
var pathname = location.pathname;
|
|
var isZhCNConfig = queryString.indexOf('zh-CN') > -1;
|
|
if (isZhCNConfig !== isZhCN(pathname)) {
|
|
location.pathname = getLocalizedPathname(pathname, isZhCNConfig)
|
|
}
|
|
}
|
|
</script>
|
|
<script src="/common.js"></script>
|
|
<script src="/index.js"></script>
|
|
</body>
|
|
</html>
|