Skip to content

Commit d4c2c06

Browse files
authored
Merge pull request #2225 from tf/inline-text-effects
Support inline text effects in via custom theme properties
2 parents 32fdc01 + ef9d242 commit d4c2c06

File tree

7 files changed

+65
-5
lines changed

7 files changed

+65
-5
lines changed

entry_types/scrolled/package/src/contentElements/heading/stories.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,29 @@ storiesOfContentElement(module, {
117117
configuration: {
118118
color: 'accent'
119119
}
120-
}
120+
},
121+
{
122+
name: 'With text effects',
123+
configuration: {
124+
typographyVariant: 'highlight',
125+
children: 'Some Heading\nText',
126+
},
127+
themeOptions: {
128+
typography: {
129+
'heading-highlight': {
130+
transform: 'rotate(-2.7deg)',
131+
'font-style': 'italic',
132+
'--text-highlight-padding': '0 0.2em',
133+
'--text-highlight-background-color': '#fff',
134+
'--text-highlight-line-height': '1.5',
135+
'--background-clip-text-fallback-color': '#000',
136+
'--background-clip-text-background': 'linear-gradient(90deg, red 0%, #ff00ff 100%)',
137+
'--background-clip-text-background-clip': 'text',
138+
'--background-clip-text-color': 'transparent',
139+
'--background-clip-text-padding': '0 0.2em 0 0'
140+
}
141+
}
142+
}
143+
},
121144
]
122145
});

entry_types/scrolled/package/src/contentElements/hotspots/Tooltip.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {insidePagerButton} from './PagerButton';
1616
import {
1717
EditableText,
1818
EditableInlineText,
19-
EditableLink,
2019
InlineFileRights,
2120
Image,
2221
Text,

entry_types/scrolled/package/src/frontend/EditableInlineText.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ import styles from './EditableInlineText.module.css';
88
export const EditableInlineText = withInlineEditingAlternative(
99
'EditableInlineText',
1010
function EditableInlineText({value, hyphens, defaultValue = ''}) {
11+
const text = value ? value[0]?.children[0]?.text : defaultValue;
12+
1113
return (
1214
<span className={classNames(styles.root,
15+
styles.textEffects,
1316
styles[`hyphens-${hyphens}`])}>
14-
{value ? value[0]?.children[0]?.text : defaultValue}
17+
<span>{text}</span>
1518
</span>
1619
);
1720
}

entry_types/scrolled/package/src/frontend/EditableInlineText.module.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,28 @@
3131
hyphens: none;
3232
word-wrap: normal;
3333
}
34+
35+
.textEffects {
36+
padding: var(--text-highlight-padding);
37+
line-height: var(--text-highlight-line-height);
38+
box-decoration-break: clone;
39+
}
40+
41+
.textEffects:not(:has([data-slate-zero-width="n"])) {
42+
background-color: var(--text-highlight-background-color);
43+
}
44+
45+
.textEffects > span {
46+
color: var(--background-clip-text-fallback-color);
47+
padding: var(--background-clip-text-padding);
48+
box-decoration-break: clone;
49+
}
50+
51+
@supports ((background-clip: text) or (-webkit-background-clip: text)) {
52+
.textEffects > span {
53+
background: var(--background-clip-text-background);
54+
background-clip: var(--background-clip-text-background-clip);
55+
color: var(--background-clip-text-color);
56+
caret-color: var(--background-clip-text-fallback-color);
57+
}
58+
}

entry_types/scrolled/package/src/frontend/Text.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import React from 'react';
22
import classNames from 'classnames';
33
import PropTypes from 'prop-types';
44

5-
import {camelize} from './utils/camelize';
6-
75
import styles from './Text.module.css';
86

97
/**

entry_types/scrolled/package/src/frontend/inlineEditing/EditableInlineText/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const EditableInlineText = memo(function EditableInlineText({
4949
<Slate editor={editor} value={cachedValue} onChange={setCachedValue}>
5050
<Editable decorate={decorateLineBreaks}
5151
onKeyDown={handleKeyDown}
52+
renderElement={props => <Element {...props} />}
5253
renderLeaf={renderLeaf} />
5354
</Slate>
5455
<TextPlaceholder text={placeholder}
@@ -57,6 +58,16 @@ export const EditableInlineText = memo(function EditableInlineText({
5758
);
5859
});
5960

61+
function Element({attributes, children, element}) {
62+
return (
63+
<div {...attributes} style={{position: 'relative'}}>
64+
<span className={frontendStyles.textEffects}>
65+
{children}
66+
</span>
67+
</div>
68+
);
69+
}
70+
6071
function renderLeaf({attributes, children, leaf}) {
6172
if (leaf.shy) {
6273
children = <span className={styles.shy}>{children}</span>;

entry_types/scrolled/package/src/frontend/inlineEditing/EditableInlineText/index.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.shy [data-slate-string],
22
.newLine {
33
position: relative;
4+
color: var(--background-clip-text-fallback-color);
45
}
56

67
.selected.manualHyphens .shy [data-slate-string]::before {

0 commit comments

Comments
 (0)