Skip to content

Commit

Permalink
Merge pull request #3704 from udecode/fix/default-leaf
Browse files Browse the repository at this point in the history
Fix DefaultLeaf props
  • Loading branch information
zbeyens authored Nov 1, 2024
2 parents 64df4f7 + 9d55a4d commit ef32ccb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-rockets-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-core': patch
---

Fix DefaultLeaf props
42 changes: 30 additions & 12 deletions packages/core/src/react/components/DefaultLeaf.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import React from 'react';

import type { PlateRenderLeafProps } from '../plugin/PlateRenderLeafProps';

export function DefaultLeaf({
attributes,
children,
style,
}: PlateRenderLeafProps & { style?: React.CSSProperties }) {
return (
<span {...attributes} style={style}>
{children}
</span>
);
import type { TText } from '@udecode/slate';

import { clsx } from 'clsx';

import { type PlateRenderLeafProps, omitPluginContext } from '../plugin';

type DefaultLeafProps = {
leafToAttributes?: (leaf: TText) => any;
} & PlateRenderLeafProps &
React.HTMLAttributes<HTMLSpanElement>;

const useDefaultLeaf = (props: DefaultLeafProps) => {
const { attributes, leaf, leafToAttributes, nodeProps, text, ...rootProps } =
omitPluginContext(props as any);

return {
props: {
...attributes,
...rootProps,
...nodeProps,
...leafToAttributes?.(leaf),
className: clsx(props.className, nodeProps?.className),
},
};
};

export function DefaultLeaf(props: DefaultLeafProps) {
const { props: rootProps } = useDefaultLeaf(props);

return <span {...rootProps} />;
}

0 comments on commit ef32ccb

Please sign in to comment.