index18.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. import { g as oo, m as eo, d as I, r as j, a3 as to, b8 as V, y as A, u as H, o as ro, c as K, _ as D, P as L, M as E, O as z, Q as _, j as no } from "./index2.js";
  2. import { provide as U, inject as N, defineComponent as M, computed as O, ref as F, createVNode as T, watch as io, nextTick as ao } from "vue";
  3. import { V as lo } from "./Checkbox.js";
  4. import { u as X, F as so } from "./FormItemContext.js";
  5. const Q = Symbol("radioGroupContextKey"), co = (o) => {
  6. U(Q, o);
  7. }, uo = () => N(Q, void 0), q = Symbol("radioOptionTypeContextKey"), po = (o) => {
  8. U(q, o);
  9. }, bo = () => N(q, void 0), go = new to("antRadioEffect", {
  10. "0%": {
  11. transform: "scale(1)",
  12. opacity: 0.5
  13. },
  14. "100%": {
  15. transform: "scale(1.6)",
  16. opacity: 0
  17. }
  18. }), ho = (o) => {
  19. const {
  20. componentCls: r,
  21. antCls: n
  22. } = o, t = `${r}-group`;
  23. return {
  24. [t]: I(I({}, j(o)), {
  25. display: "inline-block",
  26. fontSize: 0,
  27. // RTL
  28. [`&${t}-rtl`]: {
  29. direction: "rtl"
  30. },
  31. [`${n}-badge ${n}-badge-count`]: {
  32. zIndex: 1
  33. },
  34. [`> ${n}-badge:not(:first-child) > ${n}-button-wrapper`]: {
  35. borderInlineStart: "none"
  36. }
  37. })
  38. };
  39. }, Co = (o) => {
  40. const {
  41. componentCls: r,
  42. radioWrapperMarginRight: n,
  43. radioCheckedColor: t,
  44. radioSize: e,
  45. motionDurationSlow: d,
  46. motionDurationMid: s,
  47. motionEaseInOut: w,
  48. motionEaseInOutCirc: C,
  49. radioButtonBg: b,
  50. colorBorder: B,
  51. lineWidth: g,
  52. radioDotSize: f,
  53. colorBgContainerDisabled: y,
  54. colorTextDisabled: c,
  55. paddingXS: h,
  56. radioDotDisabledColor: i,
  57. lineType: m,
  58. radioDotDisabledSize: u,
  59. wireframe: p,
  60. colorWhite: x
  61. } = o, a = `${r}-inner`;
  62. return {
  63. [`${r}-wrapper`]: I(I({}, j(o)), {
  64. position: "relative",
  65. display: "inline-flex",
  66. alignItems: "baseline",
  67. marginInlineStart: 0,
  68. marginInlineEnd: n,
  69. cursor: "pointer",
  70. // RTL
  71. [`&${r}-wrapper-rtl`]: {
  72. direction: "rtl"
  73. },
  74. "&-disabled": {
  75. cursor: "not-allowed",
  76. color: o.colorTextDisabled
  77. },
  78. "&::after": {
  79. display: "inline-block",
  80. width: 0,
  81. overflow: "hidden",
  82. content: '"\\a0"'
  83. },
  84. // hashId 在 wrapper 上,只能铺平
  85. [`${r}-checked::after`]: {
  86. position: "absolute",
  87. insetBlockStart: 0,
  88. insetInlineStart: 0,
  89. width: "100%",
  90. height: "100%",
  91. border: `${g}px ${m} ${t}`,
  92. borderRadius: "50%",
  93. visibility: "hidden",
  94. animationName: go,
  95. animationDuration: d,
  96. animationTimingFunction: w,
  97. animationFillMode: "both",
  98. content: '""'
  99. },
  100. [r]: I(I({}, j(o)), {
  101. position: "relative",
  102. display: "inline-block",
  103. outline: "none",
  104. cursor: "pointer",
  105. alignSelf: "center"
  106. }),
  107. [`${r}-wrapper:hover &,
  108. &:hover ${a}`]: {
  109. borderColor: t
  110. },
  111. [`${r}-input:focus-visible + ${a}`]: I({}, V(o)),
  112. [`${r}:hover::after, ${r}-wrapper:hover &::after`]: {
  113. visibility: "visible"
  114. },
  115. [`${r}-inner`]: {
  116. "&::after": {
  117. boxSizing: "border-box",
  118. position: "absolute",
  119. insetBlockStart: "50%",
  120. insetInlineStart: "50%",
  121. display: "block",
  122. width: e,
  123. height: e,
  124. marginBlockStart: e / -2,
  125. marginInlineStart: e / -2,
  126. backgroundColor: p ? t : x,
  127. borderBlockStart: 0,
  128. borderInlineStart: 0,
  129. borderRadius: e,
  130. transform: "scale(0)",
  131. opacity: 0,
  132. transition: `all ${d} ${C}`,
  133. content: '""'
  134. },
  135. boxSizing: "border-box",
  136. position: "relative",
  137. insetBlockStart: 0,
  138. insetInlineStart: 0,
  139. display: "block",
  140. width: e,
  141. height: e,
  142. backgroundColor: b,
  143. borderColor: B,
  144. borderStyle: "solid",
  145. borderWidth: g,
  146. borderRadius: "50%",
  147. transition: `all ${s}`
  148. },
  149. [`${r}-input`]: {
  150. position: "absolute",
  151. insetBlockStart: 0,
  152. insetInlineEnd: 0,
  153. insetBlockEnd: 0,
  154. insetInlineStart: 0,
  155. zIndex: 1,
  156. cursor: "pointer",
  157. opacity: 0
  158. },
  159. // 选中状态
  160. [`${r}-checked`]: {
  161. [a]: {
  162. borderColor: t,
  163. backgroundColor: p ? b : t,
  164. "&::after": {
  165. transform: `scale(${f / e})`,
  166. opacity: 1,
  167. transition: `all ${d} ${C}`
  168. }
  169. }
  170. },
  171. [`${r}-disabled`]: {
  172. cursor: "not-allowed",
  173. [a]: {
  174. backgroundColor: y,
  175. borderColor: B,
  176. cursor: "not-allowed",
  177. "&::after": {
  178. backgroundColor: i
  179. }
  180. },
  181. [`${r}-input`]: {
  182. cursor: "not-allowed"
  183. },
  184. [`${r}-disabled + span`]: {
  185. color: c,
  186. cursor: "not-allowed"
  187. },
  188. [`&${r}-checked`]: {
  189. [a]: {
  190. "&::after": {
  191. transform: `scale(${u / e})`
  192. }
  193. }
  194. }
  195. },
  196. [`span${r} + *`]: {
  197. paddingInlineStart: h,
  198. paddingInlineEnd: h
  199. }
  200. })
  201. };
  202. }, fo = (o) => {
  203. const {
  204. radioButtonColor: r,
  205. controlHeight: n,
  206. componentCls: t,
  207. lineWidth: e,
  208. lineType: d,
  209. colorBorder: s,
  210. motionDurationSlow: w,
  211. motionDurationMid: C,
  212. radioButtonPaddingHorizontal: b,
  213. fontSize: B,
  214. radioButtonBg: g,
  215. fontSizeLG: f,
  216. controlHeightLG: y,
  217. controlHeightSM: c,
  218. paddingXS: h,
  219. borderRadius: i,
  220. borderRadiusSM: m,
  221. borderRadiusLG: u,
  222. radioCheckedColor: p,
  223. radioButtonCheckedBg: x,
  224. radioButtonHoverColor: a,
  225. radioButtonActiveColor: v,
  226. radioSolidCheckedColor: R,
  227. colorTextDisabled: l,
  228. colorBgContainerDisabled: S,
  229. radioDisabledButtonCheckedColor: P,
  230. radioDisabledButtonCheckedBg: G
  231. } = o;
  232. return {
  233. [`${t}-button-wrapper`]: {
  234. position: "relative",
  235. display: "inline-block",
  236. height: n,
  237. margin: 0,
  238. paddingInline: b,
  239. paddingBlock: 0,
  240. color: r,
  241. fontSize: B,
  242. lineHeight: `${n - e * 2}px`,
  243. background: g,
  244. border: `${e}px ${d} ${s}`,
  245. // strange align fix for chrome but works
  246. // https://gw.alipayobjects.com/zos/rmsportal/VFTfKXJuogBAXcvfAUWJ.gif
  247. borderBlockStartWidth: e + 0.02,
  248. borderInlineStartWidth: 0,
  249. borderInlineEndWidth: e,
  250. cursor: "pointer",
  251. transition: [`color ${C}`, `background ${C}`, `border-color ${C}`, `box-shadow ${C}`].join(","),
  252. a: {
  253. color: r
  254. },
  255. [`> ${t}-button`]: {
  256. position: "absolute",
  257. insetBlockStart: 0,
  258. insetInlineStart: 0,
  259. zIndex: -1,
  260. width: "100%",
  261. height: "100%"
  262. },
  263. "&:not(:first-child)": {
  264. "&::before": {
  265. position: "absolute",
  266. insetBlockStart: -e,
  267. insetInlineStart: -e,
  268. display: "block",
  269. boxSizing: "content-box",
  270. width: 1,
  271. height: "100%",
  272. paddingBlock: e,
  273. paddingInline: 0,
  274. backgroundColor: s,
  275. transition: `background-color ${w}`,
  276. content: '""'
  277. }
  278. },
  279. "&:first-child": {
  280. borderInlineStart: `${e}px ${d} ${s}`,
  281. borderStartStartRadius: i,
  282. borderEndStartRadius: i
  283. },
  284. "&:last-child": {
  285. borderStartEndRadius: i,
  286. borderEndEndRadius: i
  287. },
  288. "&:first-child:last-child": {
  289. borderRadius: i
  290. },
  291. [`${t}-group-large &`]: {
  292. height: y,
  293. fontSize: f,
  294. lineHeight: `${y - e * 2}px`,
  295. "&:first-child": {
  296. borderStartStartRadius: u,
  297. borderEndStartRadius: u
  298. },
  299. "&:last-child": {
  300. borderStartEndRadius: u,
  301. borderEndEndRadius: u
  302. }
  303. },
  304. [`${t}-group-small &`]: {
  305. height: c,
  306. paddingInline: h - e,
  307. paddingBlock: 0,
  308. lineHeight: `${c - e * 2}px`,
  309. "&:first-child": {
  310. borderStartStartRadius: m,
  311. borderEndStartRadius: m
  312. },
  313. "&:last-child": {
  314. borderStartEndRadius: m,
  315. borderEndEndRadius: m
  316. }
  317. },
  318. "&:hover": {
  319. position: "relative",
  320. color: p
  321. },
  322. "&:has(:focus-visible)": I({}, V(o)),
  323. [`${t}-inner, input[type='checkbox'], input[type='radio']`]: {
  324. width: 0,
  325. height: 0,
  326. opacity: 0,
  327. pointerEvents: "none"
  328. },
  329. [`&-checked:not(${t}-button-wrapper-disabled)`]: {
  330. zIndex: 1,
  331. color: p,
  332. background: x,
  333. borderColor: p,
  334. "&::before": {
  335. backgroundColor: p
  336. },
  337. "&:first-child": {
  338. borderColor: p
  339. },
  340. "&:hover": {
  341. color: a,
  342. borderColor: a,
  343. "&::before": {
  344. backgroundColor: a
  345. }
  346. },
  347. "&:active": {
  348. color: v,
  349. borderColor: v,
  350. "&::before": {
  351. backgroundColor: v
  352. }
  353. }
  354. },
  355. [`${t}-group-solid &-checked:not(${t}-button-wrapper-disabled)`]: {
  356. color: R,
  357. background: p,
  358. borderColor: p,
  359. "&:hover": {
  360. color: R,
  361. background: a,
  362. borderColor: a
  363. },
  364. "&:active": {
  365. color: R,
  366. background: v,
  367. borderColor: v
  368. }
  369. },
  370. "&-disabled": {
  371. color: l,
  372. backgroundColor: S,
  373. borderColor: s,
  374. cursor: "not-allowed",
  375. "&:first-child, &:hover": {
  376. color: l,
  377. backgroundColor: S,
  378. borderColor: s
  379. }
  380. },
  381. [`&-disabled${t}-button-wrapper-checked`]: {
  382. color: P,
  383. backgroundColor: G,
  384. borderColor: s,
  385. boxShadow: "none"
  386. }
  387. }
  388. };
  389. }, J = oo("Radio", (o) => {
  390. const {
  391. padding: r,
  392. lineWidth: n,
  393. controlItemBgActiveDisabled: t,
  394. colorTextDisabled: e,
  395. colorBgContainer: d,
  396. fontSizeLG: s,
  397. controlOutline: w,
  398. colorPrimaryHover: C,
  399. colorPrimaryActive: b,
  400. colorText: B,
  401. colorPrimary: g,
  402. marginXS: f,
  403. controlOutlineWidth: y,
  404. colorTextLightSolid: c,
  405. wireframe: h
  406. } = o, i = `0 0 0 ${y}px ${w}`, m = i, u = s, p = 4, x = u - p * 2, a = h ? x : u - (p + n) * 2, v = g, R = B, l = C, S = b, P = r - n, $ = eo(o, {
  407. radioFocusShadow: i,
  408. radioButtonFocusShadow: m,
  409. radioSize: u,
  410. radioDotSize: a,
  411. radioDotDisabledSize: x,
  412. radioCheckedColor: v,
  413. radioDotDisabledColor: e,
  414. radioSolidCheckedColor: c,
  415. radioButtonBg: d,
  416. radioButtonCheckedBg: d,
  417. radioButtonColor: R,
  418. radioButtonHoverColor: l,
  419. radioButtonActiveColor: S,
  420. radioButtonPaddingHorizontal: P,
  421. radioDisabledButtonCheckedBg: t,
  422. radioDisabledButtonCheckedColor: e,
  423. radioWrapperMarginRight: f
  424. });
  425. return [ho($), Co($), fo($)];
  426. });
  427. var vo = function(o, r) {
  428. var n = {};
  429. for (var t in o) Object.prototype.hasOwnProperty.call(o, t) && r.indexOf(t) < 0 && (n[t] = o[t]);
  430. if (o != null && typeof Object.getOwnPropertySymbols == "function") for (var e = 0, t = Object.getOwnPropertySymbols(o); e < t.length; e++)
  431. r.indexOf(t[e]) < 0 && Object.prototype.propertyIsEnumerable.call(o, t[e]) && (n[t[e]] = o[t[e]]);
  432. return n;
  433. };
  434. const Y = () => ({
  435. prefixCls: String,
  436. checked: z(),
  437. disabled: z(),
  438. isGroup: z(),
  439. value: L.any,
  440. name: String,
  441. id: String,
  442. autofocus: z(),
  443. onChange: E(),
  444. onFocus: E(),
  445. onBlur: E(),
  446. onClick: E(),
  447. "onUpdate:checked": E(),
  448. "onUpdate:value": E()
  449. }), k = M({
  450. compatConfig: {
  451. MODE: 3
  452. },
  453. name: "ARadio",
  454. inheritAttrs: !1,
  455. props: Y(),
  456. setup(o, r) {
  457. let {
  458. emit: n,
  459. expose: t,
  460. slots: e,
  461. attrs: d
  462. } = r;
  463. const s = X(), w = so.useInject(), C = bo(), b = uo(), B = A(), g = O(() => {
  464. var l;
  465. return (l = h.value) !== null && l !== void 0 ? l : B.value;
  466. }), f = F(), {
  467. prefixCls: y,
  468. direction: c,
  469. disabled: h
  470. } = H("radio", o), i = O(() => (b == null ? void 0 : b.optionType.value) === "button" || C === "button" ? `${y.value}-button` : y.value), m = A(), [u, p] = J(y);
  471. t({
  472. focus: () => {
  473. f.value.focus();
  474. },
  475. blur: () => {
  476. f.value.blur();
  477. }
  478. });
  479. const v = (l) => {
  480. const S = l.target.checked;
  481. n("update:checked", S), n("update:value", S), n("change", l), s.onFieldChange();
  482. }, R = (l) => {
  483. n("change", l), b && b.onChange && b.onChange(l);
  484. };
  485. return () => {
  486. var l;
  487. const S = b, {
  488. prefixCls: P,
  489. id: G = s.id.value
  490. } = o, W = vo(o, ["prefixCls", "id"]), $ = I(I({
  491. prefixCls: i.value,
  492. id: G
  493. }, ro(W, ["onUpdate:checked", "onUpdate:value"])), {
  494. disabled: (l = h.value) !== null && l !== void 0 ? l : m.value
  495. });
  496. S ? ($.name = S.name.value, $.onChange = R, $.checked = o.value === S.value.value, $.disabled = g.value || S.disabled.value) : $.onChange = v;
  497. const Z = K({
  498. [`${i.value}-wrapper`]: !0,
  499. [`${i.value}-wrapper-checked`]: $.checked,
  500. [`${i.value}-wrapper-disabled`]: $.disabled,
  501. [`${i.value}-wrapper-rtl`]: c.value === "rtl",
  502. [`${i.value}-wrapper-in-form-item`]: w.isFormItemInput
  503. }, d.class, p.value);
  504. return u(T("label", D(D({}, d), {}, {
  505. class: Z
  506. }), [T(lo, D(D({}, $), {}, {
  507. type: "radio",
  508. ref: f
  509. }), null), e.default && T("span", null, [e.default()])]));
  510. };
  511. }
  512. }), mo = () => ({
  513. prefixCls: String,
  514. value: L.any,
  515. size: _(),
  516. options: no(),
  517. disabled: z(),
  518. name: String,
  519. buttonStyle: _("outline"),
  520. id: String,
  521. optionType: _("default"),
  522. onChange: E(),
  523. "onUpdate:value": E()
  524. }), So = M({
  525. compatConfig: {
  526. MODE: 3
  527. },
  528. name: "ARadioGroup",
  529. inheritAttrs: !1,
  530. props: mo(),
  531. // emits: ['update:value', 'change'],
  532. setup(o, r) {
  533. let {
  534. slots: n,
  535. emit: t,
  536. attrs: e
  537. } = r;
  538. const d = X(), {
  539. prefixCls: s,
  540. direction: w,
  541. size: C
  542. } = H("radio", o), [b, B] = J(s), g = F(o.value), f = F(!1);
  543. return io(() => o.value, (c) => {
  544. g.value = c, f.value = !1;
  545. }), co({
  546. onChange: (c) => {
  547. const h = g.value, {
  548. value: i
  549. } = c.target;
  550. "value" in o || (g.value = i), !f.value && i !== h && (f.value = !0, t("update:value", i), t("change", c), d.onFieldChange()), ao(() => {
  551. f.value = !1;
  552. });
  553. },
  554. value: g,
  555. disabled: O(() => o.disabled),
  556. name: O(() => o.name),
  557. optionType: O(() => o.optionType)
  558. }), () => {
  559. var c;
  560. const {
  561. options: h,
  562. buttonStyle: i,
  563. id: m = d.id.value
  564. } = o, u = `${s.value}-group`, p = K(u, `${u}-${i}`, {
  565. [`${u}-${C.value}`]: C.value,
  566. [`${u}-rtl`]: w.value === "rtl"
  567. }, e.class, B.value);
  568. let x = null;
  569. return h && h.length > 0 ? x = h.map((a) => {
  570. if (typeof a == "string" || typeof a == "number")
  571. return T(k, {
  572. key: a,
  573. prefixCls: s.value,
  574. disabled: o.disabled,
  575. value: a,
  576. checked: g.value === a
  577. }, {
  578. default: () => [a]
  579. });
  580. const {
  581. value: v,
  582. disabled: R,
  583. label: l
  584. } = a;
  585. return T(k, {
  586. key: `radio-group-value-options-${v}`,
  587. prefixCls: s.value,
  588. disabled: R || o.disabled,
  589. value: v,
  590. checked: g.value === v
  591. }, {
  592. default: () => [l]
  593. });
  594. }) : x = (c = n.default) === null || c === void 0 ? void 0 : c.call(n), b(T("div", D(D({}, e), {}, {
  595. class: p,
  596. id: m
  597. }), [x]));
  598. };
  599. }
  600. }), $o = M({
  601. compatConfig: {
  602. MODE: 3
  603. },
  604. name: "ARadioButton",
  605. inheritAttrs: !1,
  606. props: Y(),
  607. setup(o, r) {
  608. let {
  609. slots: n,
  610. attrs: t
  611. } = r;
  612. const {
  613. prefixCls: e
  614. } = H("radio", o);
  615. return po("button"), () => {
  616. var d;
  617. return T(k, D(D(D({}, t), o), {}, {
  618. prefixCls: e.value
  619. }), {
  620. default: () => [(d = n.default) === null || d === void 0 ? void 0 : d.call(n)]
  621. });
  622. };
  623. }
  624. });
  625. k.Group = So;
  626. k.Button = $o;
  627. k.install = function(o) {
  628. return o.component(k.name, k), o.component(k.Group.name, k.Group), o.component(k.Button.name, k.Button), o;
  629. };
  630. export {
  631. k as R,
  632. So as _
  633. };