diff --git a/packages/apsara-ui/src/Checkbox/Checkbox.styles.tsx b/packages/apsara-ui/src/Checkbox/Checkbox.styles.tsx index 4335cef8..ef407202 100644 --- a/packages/apsara-ui/src/Checkbox/Checkbox.styles.tsx +++ b/packages/apsara-ui/src/Checkbox/Checkbox.styles.tsx @@ -34,6 +34,7 @@ export const CheckboxWrapper = styled("div")` export const CheckboxGroupWrapper = styled("div")<{ orientation?: "horizontal" | "vertical" }>` display: flex; + flex-wrap: wrap; ${({ orientation }) => { return orientation === "vertical" ? css` diff --git a/packages/apsara-ui/src/Checkbox/Checkbox.tsx b/packages/apsara-ui/src/Checkbox/Checkbox.tsx index d6b66293..e0a69c1e 100644 --- a/packages/apsara-ui/src/Checkbox/Checkbox.tsx +++ b/packages/apsara-ui/src/Checkbox/Checkbox.tsx @@ -46,7 +46,7 @@ const Checkbox = ({ }, [checked]); return ( - + + {options && options.map((option, index) => (
diff --git a/packages/apsara-ui/src/Popover/Popover.stories.tsx b/packages/apsara-ui/src/Popover/Popover.stories.tsx index fb857780..edfa9e3c 100644 --- a/packages/apsara-ui/src/Popover/Popover.stories.tsx +++ b/packages/apsara-ui/src/Popover/Popover.stories.tsx @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-empty-function */ -import React from "react"; +import React, { useState } from "react"; import Popover from "./Popover"; import Button from "../Button"; @@ -10,14 +10,6 @@ export default { component: Popover, }; -export const popover = () => ( - <> - {}}> - - - -); - export const popoverContent = () => ( <> (
} - onOk={() => {}} + okBtnProps={{ + text: "ok", + style: { marginLeft: "10px" }, + }} cancelBtnProps={{ text: "Cancel", style: { marginLeft: "10px" }, @@ -37,3 +32,27 @@ export const popoverContent = () => ( ); + +export const popoverContentParam = () => { + const [open, setOpen] = useState(false); + return ( + <> + + + + } + cancelBtnProps={{ + text: "Cancel", + style: { marginLeft: "10px" }, + }} + open={open} + onOpenChange={setOpen} + > + + + + ); +}; diff --git a/packages/apsara-ui/src/Popover/Popover.styles.tsx b/packages/apsara-ui/src/Popover/Popover.styles.tsx index 9b689dae..d3ba82b4 100644 --- a/packages/apsara-ui/src/Popover/Popover.styles.tsx +++ b/packages/apsara-ui/src/Popover/Popover.styles.tsx @@ -7,7 +7,7 @@ import styled from "styled-components"; export const Container = styled.div` font-size: 12px; - width: 260px; + width: fit-content; margin: -12px -16px; `; diff --git a/packages/apsara-ui/src/Popover/Popover.tsx b/packages/apsara-ui/src/Popover/Popover.tsx index 18e518b0..5038e200 100644 --- a/packages/apsara-ui/src/Popover/Popover.tsx +++ b/packages/apsara-ui/src/Popover/Popover.tsx @@ -18,7 +18,9 @@ interface ButtonPopoverContentProps { title: string; message?: string; content?: React.ReactNode | null; - onOk: () => void; + onOpenChange?: (open: boolean) => void; + open?: boolean; + onOk?: () => void; onCancel?: () => void; okBtnProps?: { text?: string; @@ -37,7 +39,7 @@ export const PopoverContent = ({ okBtnProps = {}, cancelBtnProps = {}, }: ButtonPopoverContentProps) => { - const { text: okText = "Yes", ...restOkBtnProps } = okBtnProps; + const { text: okText, ...restOkBtnProps } = okBtnProps; const { text: cancelText, ...restCancelBtnProps } = cancelBtnProps; return ( @@ -46,16 +48,20 @@ export const PopoverContent = ({ {title} {message || content} -
- - {cancelText ? ( - - ) : null} -
+ {(okText || cancelText) && ( +
+ {okText ? ( + + ) : null} + {cancelText ? ( + + ) : null} +
+ )} ); }; @@ -68,26 +74,51 @@ function ConfirmationPopover({ title = "", message = "", content = null, + open, + onOpenChange = () => ({}), onOk, - onCancel = () => ({}), + onCancel, okBtnProps, cancelBtnProps, children, }: ButtonConfirmationPopover) { - const [open, setOpen] = useState(false); + const [internalOpen, setInternalOpen] = useState(false); + const controlled = typeof open !== "boolean"; const onOKClick = () => { - setOpen(false); - onOk(); + if (controlled) { + setInternalOpen(false); + } + if (onOk) { + onOk(); + } else if (onOpenChange) { + onOpenChange(false); + } }; const onCancelClick = () => { - setOpen(false); - onCancel(); + if (controlled) { + setInternalOpen(false); + } + if (onCancel) { + onCancel(); + } else if (onOpenChange) { + onOpenChange(false); + } }; + const finalOpen = controlled ? internalOpen : open; + return ( - setOpen(open)}> + { + if (controlled) setInternalOpen(value); + else { + onOpenChange && onOpenChange(value); + } + }} + > {children}