@chakra-ui/button
Version:
A React component that is a base button.
1 lines • 3.9 kB
Source Map (JSON)
{"version":3,"sources":["../src/button-group.tsx"],"sourcesContent":["import {\n chakra,\n forwardRef,\n HTMLChakraProps,\n SystemStyleObject,\n ThemingProps,\n} from \"@chakra-ui/system\"\nimport { cx } from \"@chakra-ui/shared-utils\"\nimport { useMemo } from \"react\"\nimport { ButtonGroupContext, ButtonGroupProvider } from \"./button-context\"\nimport { ButtonGroupOptions } from \"./button-types\"\n\nexport interface ButtonGroupProps\n extends HTMLChakraProps<\"div\">,\n ThemingProps<\"Button\">,\n ButtonGroupOptions {}\n\nconst attachedStyles: Record<string, SystemStyleObject> = {\n horizontal: {\n \"> *:first-of-type:not(:last-of-type)\": { borderEndRadius: 0 },\n \"> *:not(:first-of-type):not(:last-of-type)\": { borderRadius: 0 },\n \"> *:not(:first-of-type):last-of-type\": { borderStartRadius: 0 },\n },\n vertical: {\n \"> *:first-of-type:not(:last-of-type)\": { borderBottomRadius: 0 },\n \"> *:not(:first-of-type):not(:last-of-type)\": { borderRadius: 0 },\n \"> *:not(:first-of-type):last-of-type\": { borderTopRadius: 0 },\n },\n}\n\nconst gapStyles = {\n horizontal: (spacing: any): SystemStyleObject => ({\n \"& > *:not(style) ~ *:not(style)\": { marginStart: spacing },\n }),\n vertical: (spacing: any): SystemStyleObject => ({\n \"& > *:not(style) ~ *:not(style)\": { marginTop: spacing },\n }),\n}\n\nexport const ButtonGroup = forwardRef<ButtonGroupProps, \"div\">(\n function ButtonGroup(props, ref) {\n const {\n size,\n colorScheme,\n variant,\n className,\n spacing = \"0.5rem\",\n isAttached,\n isDisabled,\n orientation = \"horizontal\",\n ...rest\n } = props\n\n const _className = cx(\"chakra-button__group\", className)\n\n const context: ButtonGroupContext = useMemo(\n () => ({ size, colorScheme, variant, isDisabled }),\n [size, colorScheme, variant, isDisabled],\n )\n\n let groupStyles: SystemStyleObject = {\n display: \"inline-flex\",\n ...(isAttached\n ? attachedStyles[orientation]\n : gapStyles[orientation](spacing)),\n }\n\n const isVertical = orientation === \"vertical\"\n\n return (\n <ButtonGroupProvider value={context}>\n <chakra.div\n ref={ref}\n role=\"group\"\n __css={groupStyles}\n className={_className}\n data-attached={isAttached ? \"\" : undefined}\n data-orientation={orientation}\n flexDir={isVertical ? \"column\" : undefined}\n {...rest}\n />\n </ButtonGroupProvider>\n )\n },\n)\n\nButtonGroup.displayName = \"ButtonGroup\"\n"],"mappings":";;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AACP,SAAS,UAAU;AACnB,SAAS,eAAe;AA+DhB;AAtDR,IAAM,iBAAoD;AAAA,EACxD,YAAY;AAAA,IACV,wCAAwC,EAAE,iBAAiB,EAAE;AAAA,IAC7D,8CAA8C,EAAE,cAAc,EAAE;AAAA,IAChE,wCAAwC,EAAE,mBAAmB,EAAE;AAAA,EACjE;AAAA,EACA,UAAU;AAAA,IACR,wCAAwC,EAAE,oBAAoB,EAAE;AAAA,IAChE,8CAA8C,EAAE,cAAc,EAAE;AAAA,IAChE,wCAAwC,EAAE,iBAAiB,EAAE;AAAA,EAC/D;AACF;AAEA,IAAM,YAAY;AAAA,EAChB,YAAY,CAAC,aAAqC;AAAA,IAChD,mCAAmC,EAAE,aAAa,QAAQ;AAAA,EAC5D;AAAA,EACA,UAAU,CAAC,aAAqC;AAAA,IAC9C,mCAAmC,EAAE,WAAW,QAAQ;AAAA,EAC1D;AACF;AAEO,IAAM,cAAc;AAAA,EACzB,SAASA,aAAY,OAAO,KAAK;AAC/B,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,GAAG;AAAA,IACL,IAAI;AAEJ,UAAM,aAAa,GAAG,wBAAwB,SAAS;AAEvD,UAAM,UAA8B;AAAA,MAClC,OAAO,EAAE,MAAM,aAAa,SAAS,WAAW;AAAA,MAChD,CAAC,MAAM,aAAa,SAAS,UAAU;AAA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