mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-09 08:46:35 +02:00
* incremental upgrade to React 18, TS 4.9, etc. * update yarn config * fix build * minor cleanup in type definitions * incremental updates for TS 5.0 * fix build * upgrade to typescript 5.2 * update dependencies * fix lint issues * update to latest Playwright version * update changesets dep * update emotion/css * incremental dependency updates * more small dependency updates * upgrade prettier and eslint * fix lint issues * update dependencies rollup * fix @types/node resolution to restore linting * update tiny-invariant dependency * update dependencies * update dependencies lerna * upgrade react-router-dom * update @types/react and @types/node * update babel dependencies * udpate simple-git-hooks * update @types/node resolution * update lint-staged * remove cypress from dependency list * update @types/node to support Node 20 * update workflows to Node 20 * set resolutions for @types/react * downgrade @types/react to 18.2.28 * update mocha * update rimraf * update @types/js-dom * remove .lintstagedrc.js * upgrade next to latest * v0.61.4 * update lerna * update faker and rollup * update immer * fix yarn clean command * attempt to fix integration tests * attempt to stabilize integration tests * wip fix integration tests * skip unstable integration test * Add changeset --------- Co-authored-by: Dalibor Tosic <dalibortosic00@gmail.com> Co-authored-by: Nikola <nikolabijelic14@gmail.com>
197 lines
3.7 KiB
TypeScript
197 lines
3.7 KiB
TypeScript
import React, { ReactNode, Ref, PropsWithChildren } from 'react'
|
|
import ReactDOM from 'react-dom'
|
|
import { cx, css } from '@emotion/css'
|
|
|
|
interface BaseProps {
|
|
className: string
|
|
[key: string]: unknown
|
|
}
|
|
type OrNull<T> = T | null
|
|
|
|
export const Button = React.forwardRef(
|
|
(
|
|
{
|
|
className,
|
|
active,
|
|
reversed,
|
|
...props
|
|
}: PropsWithChildren<
|
|
{
|
|
active: boolean
|
|
reversed: boolean
|
|
} & BaseProps
|
|
>,
|
|
ref: Ref<OrNull<HTMLSpanElement>>
|
|
) => (
|
|
<span
|
|
{...props}
|
|
ref={ref}
|
|
className={cx(
|
|
className,
|
|
css`
|
|
cursor: pointer;
|
|
color: ${reversed
|
|
? active
|
|
? 'white'
|
|
: '#aaa'
|
|
: active
|
|
? 'black'
|
|
: '#ccc'};
|
|
`
|
|
)}
|
|
/>
|
|
)
|
|
)
|
|
|
|
export const EditorValue = React.forwardRef(
|
|
(
|
|
{
|
|
className,
|
|
value,
|
|
...props
|
|
}: PropsWithChildren<
|
|
{
|
|
value: any
|
|
} & BaseProps
|
|
>,
|
|
ref: Ref<OrNull<null>>
|
|
) => {
|
|
const textLines = value.document.nodes
|
|
.map(node => node.text)
|
|
.toArray()
|
|
.join('\n')
|
|
return (
|
|
<div
|
|
ref={ref}
|
|
{...props}
|
|
className={cx(
|
|
className,
|
|
css`
|
|
margin: 30px -20px 0;
|
|
`
|
|
)}
|
|
>
|
|
<div
|
|
className={css`
|
|
font-size: 14px;
|
|
padding: 5px 20px;
|
|
color: #404040;
|
|
border-top: 2px solid #eeeeee;
|
|
background: #f8f8f8;
|
|
`}
|
|
>
|
|
Slate's value as text
|
|
</div>
|
|
<div
|
|
className={css`
|
|
color: #404040;
|
|
font: 12px monospace;
|
|
white-space: pre-wrap;
|
|
padding: 10px 20px;
|
|
div {
|
|
margin: 0 0 0.5em;
|
|
}
|
|
`}
|
|
>
|
|
{textLines}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
)
|
|
|
|
export const Icon = React.forwardRef(
|
|
(
|
|
{ className, ...props }: PropsWithChildren<BaseProps>,
|
|
ref: Ref<OrNull<HTMLSpanElement>>
|
|
) => (
|
|
<span
|
|
{...props}
|
|
ref={ref}
|
|
className={cx(
|
|
'material-icons',
|
|
className,
|
|
css`
|
|
font-size: 18px;
|
|
vertical-align: text-bottom;
|
|
`
|
|
)}
|
|
/>
|
|
)
|
|
)
|
|
|
|
export const Instruction = React.forwardRef(
|
|
(
|
|
{ className, ...props }: PropsWithChildren<BaseProps>,
|
|
ref: Ref<OrNull<HTMLDivElement>>
|
|
) => (
|
|
<div
|
|
{...props}
|
|
ref={ref}
|
|
className={cx(
|
|
className,
|
|
css`
|
|
white-space: pre-wrap;
|
|
margin: 0 -20px 10px;
|
|
padding: 10px 20px;
|
|
font-size: 14px;
|
|
background: #f8f8e8;
|
|
`
|
|
)}
|
|
/>
|
|
)
|
|
)
|
|
|
|
export const Menu = React.forwardRef(
|
|
(
|
|
{ className, ...props }: PropsWithChildren<BaseProps>,
|
|
ref: Ref<OrNull<HTMLDivElement>>
|
|
) => (
|
|
<div
|
|
{...props}
|
|
data-test-id="menu"
|
|
ref={ref}
|
|
className={cx(
|
|
className,
|
|
css`
|
|
& > * {
|
|
display: inline-block;
|
|
}
|
|
|
|
& > * + * {
|
|
margin-left: 15px;
|
|
}
|
|
`
|
|
)}
|
|
/>
|
|
)
|
|
)
|
|
|
|
export const Portal = ({ children }: { children?: ReactNode }) => {
|
|
return typeof document === 'object'
|
|
? ReactDOM.createPortal(children, document.body)
|
|
: null
|
|
}
|
|
|
|
export const Toolbar = React.forwardRef(
|
|
(
|
|
{ className, ...props }: PropsWithChildren<BaseProps>,
|
|
ref: Ref<OrNull<HTMLDivElement>>
|
|
) => (
|
|
<Menu
|
|
{...props}
|
|
ref={ref}
|
|
className={cx(
|
|
className,
|
|
css`
|
|
position: relative;
|
|
padding: 1px 18px 17px;
|
|
margin: 0 -20px;
|
|
border-bottom: 2px solid #eee;
|
|
margin-bottom: 20px;
|
|
`
|
|
)}
|
|
/>
|
|
)
|
|
)
|