feat: make markdown toolbar sticky (#713)
This commit is contained in:
parent
d4f56da6e7
commit
39bb9647b2
@ -1,5 +1,6 @@
|
|||||||
import OptionUnstyled from '@mui/base/OptionUnstyled';
|
import OptionUnstyled from '@mui/base/OptionUnstyled';
|
||||||
import SelectUnstyled from '@mui/base/SelectUnstyled';
|
import SelectUnstyled from '@mui/base/SelectUnstyled';
|
||||||
|
import { UnfoldMore as UnfoldMoreIcon } from '@styled-icons/material/UnfoldMore';
|
||||||
import {
|
import {
|
||||||
ELEMENT_H1,
|
ELEMENT_H1,
|
||||||
ELEMENT_H2,
|
ELEMENT_H2,
|
||||||
@ -18,6 +19,7 @@ import useDebounce from '@staticcms/core/lib/hooks/useDebounce';
|
|||||||
import classNames from '@staticcms/core/lib/util/classNames.util';
|
import classNames from '@staticcms/core/lib/util/classNames.util';
|
||||||
import { useMdPlateEditorState } from '@staticcms/markdown/plate/plateTypes';
|
import { useMdPlateEditorState } from '@staticcms/markdown/plate/plateTypes';
|
||||||
|
|
||||||
|
import type { SelectUnstyledRootSlotProps } from '@mui/base/SelectUnstyled';
|
||||||
import type { FC, FocusEvent, KeyboardEvent, MouseEvent } from 'react';
|
import type { FC, FocusEvent, KeyboardEvent, MouseEvent } from 'react';
|
||||||
|
|
||||||
type Option = {
|
type Option = {
|
||||||
@ -56,6 +58,19 @@ const types: Option[] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const Button = React.forwardRef(function Button<TValue extends {}, Multiple extends boolean>(
|
||||||
|
props: SelectUnstyledRootSlotProps<TValue, Multiple>,
|
||||||
|
ref: React.ForwardedRef<HTMLButtonElement>,
|
||||||
|
) {
|
||||||
|
const { ownerState: _, children, ...other } = props;
|
||||||
|
return (
|
||||||
|
<button type="button" {...other} ref={ref}>
|
||||||
|
{children}
|
||||||
|
<UnfoldMoreIcon className="w-4 h-4 absolute right-0" />
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
export interface FontTypeSelectProps {
|
export interface FontTypeSelectProps {
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
}
|
}
|
||||||
@ -108,12 +123,16 @@ const FontTypeSelect: FC<FontTypeSelectProps> = ({ disabled = false }) => {
|
|||||||
value={value?.value ?? ELEMENT_PARAGRAPH}
|
value={value?.value ?? ELEMENT_PARAGRAPH}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
slots={{
|
||||||
|
root: Button,
|
||||||
|
}}
|
||||||
slotProps={{
|
slotProps={{
|
||||||
root: {
|
root: {
|
||||||
className: classNames(
|
className: classNames(
|
||||||
`
|
`
|
||||||
flex
|
flex
|
||||||
items-center
|
items-center
|
||||||
|
justify-between
|
||||||
text-sm
|
text-sm
|
||||||
font-medium
|
font-medium
|
||||||
relative
|
relative
|
||||||
|
@ -15,6 +15,7 @@ const Heading1: FC<PlateRenderElementProps<MdValue, MdH1Element>> = ({
|
|||||||
{...nodeProps}
|
{...nodeProps}
|
||||||
className="
|
className="
|
||||||
text-[2em]
|
text-[2em]
|
||||||
|
leading-[1.5em]
|
||||||
font-bold
|
font-bold
|
||||||
my-[0.67em]
|
my-[0.67em]
|
||||||
"
|
"
|
||||||
|
@ -15,6 +15,7 @@ const Heading2: FC<PlateRenderElementProps<MdValue, MdH2Element>> = ({
|
|||||||
{...nodeProps}
|
{...nodeProps}
|
||||||
className="
|
className="
|
||||||
text-[1.5em]
|
text-[1.5em]
|
||||||
|
leading-[1.25em]
|
||||||
font-bold
|
font-bold
|
||||||
my-[0.83em]
|
my-[0.83em]
|
||||||
"
|
"
|
||||||
|
@ -15,6 +15,7 @@ const Heading3: FC<PlateRenderElementProps<MdValue, MdH3Element>> = ({
|
|||||||
{...nodeProps}
|
{...nodeProps}
|
||||||
className="
|
className="
|
||||||
text-[1.17em]
|
text-[1.17em]
|
||||||
|
leading-[1.25em]
|
||||||
font-bold
|
font-bold
|
||||||
my-[1em]
|
my-[1em]
|
||||||
"
|
"
|
||||||
|
@ -14,6 +14,7 @@ const Heading4: FC<PlateRenderElementProps<MdValue, MdH4Element>> = ({
|
|||||||
{...attributes}
|
{...attributes}
|
||||||
{...nodeProps}
|
{...nodeProps}
|
||||||
className="
|
className="
|
||||||
|
leading-[1.25em]
|
||||||
font-bold
|
font-bold
|
||||||
my-[1.33em]
|
my-[1.33em]
|
||||||
"
|
"
|
||||||
|
@ -15,6 +15,7 @@ const Heading5: FC<PlateRenderElementProps<MdValue, MdH5Element>> = ({
|
|||||||
{...nodeProps}
|
{...nodeProps}
|
||||||
className="
|
className="
|
||||||
text-[0.83em]
|
text-[0.83em]
|
||||||
|
leading-[1.25em]
|
||||||
font-bold
|
font-bold
|
||||||
my-[1.67em]
|
my-[1.67em]
|
||||||
"
|
"
|
||||||
|
@ -15,6 +15,7 @@ const Heading6: FC<PlateRenderElementProps<MdValue, MdH6Element>> = ({
|
|||||||
{...nodeProps}
|
{...nodeProps}
|
||||||
className="
|
className="
|
||||||
text-[0.67em]
|
text-[0.67em]
|
||||||
|
leading-[1.25em]
|
||||||
font-bold
|
font-bold
|
||||||
my-[2.33em]
|
my-[2.33em]
|
||||||
"
|
"
|
||||||
|
@ -39,7 +39,6 @@ const Toolbar: FC<ToolbarProps> = ({ useMdx, collection, field, disabled }) => {
|
|||||||
className="
|
className="
|
||||||
flex
|
flex
|
||||||
flex-wrap
|
flex-wrap
|
||||||
relative
|
|
||||||
items-center
|
items-center
|
||||||
select-none
|
select-none
|
||||||
min-h-markdown-toolbar
|
min-h-markdown-toolbar
|
||||||
@ -53,6 +52,11 @@ const Toolbar: FC<ToolbarProps> = ({ useMdx, collection, field, disabled }) => {
|
|||||||
border-gray-400
|
border-gray-400
|
||||||
gap-0.5
|
gap-0.5
|
||||||
shadow-md
|
shadow-md
|
||||||
|
bg-slate-50
|
||||||
|
dark:bg-slate-900
|
||||||
|
sticky
|
||||||
|
top-0
|
||||||
|
z-10
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
{groups}
|
{groups}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user