Responsive font size based on content length
The shorter, the larger font-size
This commit is contained in:
parent
e5ffdd53cf
commit
58860c334c
3 changed files with 15 additions and 0 deletions
|
@ -191,6 +191,7 @@
|
||||||
}
|
}
|
||||||
.status.large .content {
|
.status.large .content {
|
||||||
font-size: 150%;
|
font-size: 150%;
|
||||||
|
font-size: calc(100% + 50% / var(--content-text-weight));
|
||||||
}
|
}
|
||||||
.status.large .poll,
|
.status.large .poll,
|
||||||
.status.large .actions {
|
.status.large .actions {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import Loader from '../components/loader';
|
||||||
import Modal from '../components/modal';
|
import Modal from '../components/modal';
|
||||||
import NameText from '../components/name-text';
|
import NameText from '../components/name-text';
|
||||||
import enhanceContent from '../utils/enhance-content';
|
import enhanceContent from '../utils/enhance-content';
|
||||||
|
import htmlContentLength from '../utils/html-content-length';
|
||||||
import shortenNumber from '../utils/shorten-number';
|
import shortenNumber from '../utils/shorten-number';
|
||||||
import states from '../utils/states';
|
import states from '../utils/states';
|
||||||
import store from '../utils/store';
|
import store from '../utils/store';
|
||||||
|
@ -695,6 +696,14 @@ function Status({
|
||||||
class={`content-container ${
|
class={`content-container ${
|
||||||
sensitive || spoilerText ? 'has-spoiler' : ''
|
sensitive || spoilerText ? 'has-spoiler' : ''
|
||||||
} ${showSpoiler ? 'show-spoiler' : ''}`}
|
} ${showSpoiler ? 'show-spoiler' : ''}`}
|
||||||
|
style={
|
||||||
|
size === 'l' && {
|
||||||
|
'--content-text-weight':
|
||||||
|
Math.round(
|
||||||
|
(spoilerText.length + htmlContentLength(content)) / 140,
|
||||||
|
) || 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{!!spoilerText && sensitive && (
|
{!!spoilerText && sensitive && (
|
||||||
<>
|
<>
|
||||||
|
|
5
src/utils/html-content-length.js
Normal file
5
src/utils/html-content-length.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
const div = document.createElement('div');
|
||||||
|
export default (html) => {
|
||||||
|
div.innerHTML = html;
|
||||||
|
return div.innerText.length;
|
||||||
|
};
|
Loading…
Add table
Reference in a new issue