UNPKG

@react-beauty/ui-segment

Version:

ui-segment

59 lines (58 loc) 1.77 kB
import { jsx as r } from "react/jsx-runtime"; import { createContext as S, useCallback as u, useContext as b, forwardRef as c, Children as a } from "react"; import { styled as m } from "@linaria/react"; const f = /* @__PURE__ */ m("div")({ name: "ElSegmentContainer", class: "react-beauty-el-segment-container", propsAsIs: !1 }), y = /* @__PURE__ */ m("div")({ name: "ElSegmentList", class: "react-beauty-el-segment-list", propsAsIs: !1 }), C = /* @__PURE__ */ m("button")({ name: "ElSegmentItem", class: "react-beauty-el-segment-item", propsAsIs: !1 }), g = S(void 0), I = () => { const t = b(g); if (!t) throw new Error("useSegment must be used within a SegmentProvider"); return t; }, x = ({ children: t, value: e, onValueChange: n }) => { const o = u( (s) => ({ role: "tab", "aria-selected": e === s, onClick: () => n(s), "data-active": e === s }), [e, n] ); return /* @__PURE__ */ r(g.Provider, { value: { value: e, onValueChange: n, getItemProps: o }, children: t }); }, E = c(({ children: t, value: e, onValueChange: n, ...o }, s) => /* @__PURE__ */ r(x, { value: e, onValueChange: n, children: /* @__PURE__ */ r(f, { ref: s, role: "tablist", ...o, children: /* @__PURE__ */ r(y, { children: t }) }) })), v = c( ({ children: t, value: e, ...n }, o) => { const { getItemProps: s } = I(), l = s(e), p = a.toArray(t).every( (i) => typeof i == "string" || typeof i == "number" ), d = a.count(t) === 1 && !p; return /* @__PURE__ */ r( C, { ref: o, type: "button", ...l, ...n, "data-has-square-padding": d, children: t } ); } ), P = { Item: v }, j = Object.assign(E, P); export { j as Segment };