diff --git a/web/app/components/datasets/formatted-text/flavours/edit-slice.tsx b/web/app/components/datasets/formatted-text/flavours/edit-slice.tsx new file mode 100644 index 0000000000..56d4d32145 --- /dev/null +++ b/web/app/components/datasets/formatted-text/flavours/edit-slice.tsx @@ -0,0 +1,86 @@ +import { useState } from 'react' +import type { FC, ReactNode } from 'react' +import { FloatingFocusManager, autoUpdate, flip, shift, useDismiss, useFloating, useHover, useInteractions, useRole } from '@floating-ui/react' +import { RiDeleteBinLine } from '@remixicon/react' +import type { SliceProps } from './type' +import { SliceContainer, SliceContent, SliceDivider, SliceLabel } from './shared' +import classNames from '@/utils/classnames' +import ActionButton, { ActionButtonState } from '@/app/components/base/action-button' + +type EditSliceProps = SliceProps<{ + label: ReactNode + onDelete: () => void +}> + +export const EditSlice: FC = (props) => { + const { label, className, text, onDelete, ...rest } = props + const [delBtnShow, setDelBtnShow] = useState(false) + const [isDelBtnHover, setDelBtnHover] = useState(false) + + const { refs, floatingStyles, context } = useFloating({ + open: delBtnShow, + onOpenChange: setDelBtnShow, + placement: 'right', + whileElementsMounted: autoUpdate, + middleware: [ + flip(), + shift(), + ], + }) + const hover = useHover(context, {}) + const dismiss = useDismiss(context) + const role = useRole(context) + const { getReferenceProps, getFloatingProps } = useInteractions([hover, dismiss, role]) + + const isDestructive = delBtnShow && isDelBtnHover + + return ( +
+ + + {label} + + + {text} + + + {delBtnShow && +
setDelBtnHover(true)} + onMouseLeave={() => setDelBtnHover(false)} + > + { + onDelete() + setDelBtnShow(false) + }} + state={ActionButtonState.Destructive} + > + + +
+
} +
+
+ ) +} diff --git a/web/app/components/datasets/formatted-text/flavours/formatted.tsx b/web/app/components/datasets/formatted-text/flavours/formatted.tsx deleted file mode 100644 index b6f9d0467d..0000000000 --- a/web/app/components/datasets/formatted-text/flavours/formatted.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import type { FC, PropsWithChildren } from 'react' - -export type FormattedTextProps = PropsWithChildren - -export const FormattedText: FC = (props) => { - return

{props.children}

-} diff --git a/web/app/components/datasets/formatted-text/flavours/normal.tsx b/web/app/components/datasets/formatted-text/flavours/preview-slice.tsx similarity index 51% rename from web/app/components/datasets/formatted-text/flavours/normal.tsx rename to web/app/components/datasets/formatted-text/flavours/preview-slice.tsx index 8567428151..9b7ec026f3 100644 --- a/web/app/components/datasets/formatted-text/flavours/normal.tsx +++ b/web/app/components/datasets/formatted-text/flavours/preview-slice.tsx @@ -2,16 +2,14 @@ import { useState } from 'react' import type { FC, ReactNode } from 'react' import { autoUpdate, flip, inline, shift, useDismiss, useFloating, useHover, useInteractions, useRole } from '@floating-ui/react' import type { SliceProps } from './type' -import classNames from '@/utils/classnames' +import { SliceContainer, SliceContent, SliceDivider, SliceLabel } from './shared' -type NormalSliceProps = SliceProps<{ +type PreviewSliceProps = SliceProps<{ label: ReactNode tooltip: ReactNode }> -const baseStyle = 'py-[3px]' - -export const NormalSlice: FC = (props) => { +export const PreviewSlice: FC = (props) => { const { label, className, text, tooltip, ...rest } = props const [tooltipOpen, setTooltipOpen] = useState(false) const { refs, floatingStyles, context } = useFloating({ @@ -34,37 +32,23 @@ export const NormalSlice: FC = (props) => { const { getReferenceProps, getFloatingProps } = useInteractions([hover, dismiss, role]) return ( <> - - - {label} - - - {text} - - - {/* use a zero-width space to make the hover area bigger */} - ​ - - - {tooltipOpen &&
{label} + {text} + + + {tooltipOpen && {tooltip} -
} + } ) } diff --git a/web/app/components/datasets/formatted-text/flavours/shared.tsx b/web/app/components/datasets/formatted-text/flavours/shared.tsx index e69de29bb2..b8102e4ebf 100644 --- a/web/app/components/datasets/formatted-text/flavours/shared.tsx +++ b/web/app/components/datasets/formatted-text/flavours/shared.tsx @@ -0,0 +1,57 @@ +import { type ComponentProps, type FC, forwardRef } from 'react' +import classNames from '@/utils/classnames' + +const baseStyle = 'py-[3px]' + +export type SliceContainerProps = ComponentProps<'span'> + +export const SliceContainer: FC = forwardRef((props, ref) => { + const { className, ...rest } = props + return +}) +SliceContainer.displayName = 'SliceContainer' + +export type SliceLabelProps = ComponentProps<'span'> + +export const SliceLabel: FC = forwardRef((props, ref) => { + const { className, children, ...rest } = props + return + {children} + +}) +SliceLabel.displayName = 'SliceLabel' + +export type SliceContentProps = ComponentProps<'span'> + +export const SliceContent: FC = forwardRef((props, ref) => { + const { className, children, ...rest } = props + return + {children} + +}) +SliceContent.displayName = 'SliceContent' + +export type SliceDividerProps = ComponentProps<'span'> + +export const SliceDivider: FC = forwardRef((props, ref) => { + const { className, ...rest } = props + return + {/* use a zero-width space to make the hover area bigger */} + ​ + +}) +SliceDivider.displayName = 'SliceDivider' diff --git a/web/app/components/datasets/formatted-text/formatted.tsx b/web/app/components/datasets/formatted-text/formatted.tsx new file mode 100644 index 0000000000..14d339e688 --- /dev/null +++ b/web/app/components/datasets/formatted-text/formatted.tsx @@ -0,0 +1,12 @@ +import type { ComponentProps, FC } from 'react' +import classNames from '@/utils/classnames' + +export type FormattedTextProps = ComponentProps<'p'> + +export const FormattedText: FC = (props) => { + const { className, ...rest } = props + return

{props.children}

+} diff --git a/web/app/dev-preview/page.tsx b/web/app/dev-preview/page.tsx index f97640c53b..72434cafd9 100644 --- a/web/app/dev-preview/page.tsx +++ b/web/app/dev-preview/page.tsx @@ -1,16 +1,35 @@ 'use client' -import { FormattedText } from '../components/datasets/formatted-text/flavours/formatted' -import { NormalSlice } from '../components/datasets/formatted-text/flavours/normal' +import { FormattedText } from '../components/datasets/formatted-text/formatted' +import { PreviewSlice } from '../components/datasets/formatted-text/flavours/preview-slice' +import { EditSlice } from '../components/datasets/formatted-text/flavours/edit-slice' export default function Page() { return
- - - - - + + + + + + +
+ + + + + +
}