Skip to content

Commit 76f3b99

Browse files
committed
Auto resize values when they'd overflow the container
1 parent 182507f commit 76f3b99

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"styled-components-breakpoint": "^3.0.0-preview.20",
4444
"swr": "^0.2.3",
4545
"tailwindcss": "^3.0.24",
46+
"use-fit-text": "^2.4.0",
4647
"uuid": "^3.3.2",
4748
"xterm": "^4.15.0",
4849
"xterm-addon-attach": "^0.6.0",

resources/scripts/components/server/console/PowerButtons.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export default ({ className }: PowerButtonProps) => {
5151
<Can action={'control.restart'}>
5252
<Button.Text
5353
className={'w-full sm:w-24'}
54-
variant={Button.Variants.Secondary}
5554
disabled={!status}
5655
onClick={onButtonClick.bind(this, 'restart')}
5756
>
@@ -61,7 +60,6 @@ export default ({ className }: PowerButtonProps) => {
6160
<Can action={'control.stop'}>
6261
<Button.Danger
6362
className={'w-full sm:w-24'}
64-
variant={killable ? undefined : Button.Variants.Secondary}
6563
disabled={status === 'offline'}
6664
onClick={onButtonClick.bind(this, killable ? 'kill' : 'stop')}
6765
>

resources/scripts/components/server/console/ServerDetailsBlock.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,7 @@ const ServerDetailsBlock = ({ className }: { className?: string }) => {
146146
bytesToHuman(stats.rx)
147147
}
148148
</StatBlock>
149-
<StatBlock
150-
icon={faWifi}
151-
title={'Address'}
152-
description={`You can connect to your server at: ${allocation}`}
153-
>
149+
<StatBlock icon={faWifi} title={'Address'}>
154150
{allocation}
155151
</StatBlock>
156152
</div>

resources/scripts/components/server/console/StatBlock.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IconDefinition } from '@fortawesome/free-solid-svg-icons';
44
import classNames from 'classnames';
55
import Tooltip from '@/components/elements/tooltip/Tooltip';
66
import styles from './style.module.css';
7+
import useFitText from 'use-fit-text';
78

89
interface StatBlockProps {
910
title: string;
@@ -15,6 +16,8 @@ interface StatBlockProps {
1516
}
1617

1718
export default ({ title, icon, color, description, className, children }: StatBlockProps) => {
19+
const { fontSize, ref } = useFitText({ minFontSize: 8, maxFontSize: 500 });
20+
1821
return (
1922
<Tooltip arrow placement={'top'} disabled={!description} content={description || ''}>
2023
<div className={classNames(styles.stat_block, 'bg-gray-600', className)}>
@@ -28,11 +31,15 @@ export default ({ title, icon, color, description, className, children }: StatBl
2831
})}
2932
/>
3033
</div>
31-
<div className={'flex flex-col justify-center overflow-hidden'}>
34+
<div className={'flex flex-col justify-center overflow-hidden w-full'}>
3235
<p className={'font-header leading-tight text-xs md:text-sm text-gray-200'}>{title}</p>
33-
<p className={'text-base md:text-xl font-semibold text-gray-50 truncate'}>
36+
<div
37+
ref={ref}
38+
className={'h-[1.75rem] w-full font-semibold text-gray-50 truncate'}
39+
style={{ fontSize }}
40+
>
3441
{children}
35-
</p>
42+
</div>
3643
</div>
3744
</div>
3845
</Tooltip>

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7336,6 +7336,11 @@ requires-port@^1.0.0:
73367336
version "1.0.0"
73377337
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
73387338

7339+
resize-observer-polyfill@^1.5.1:
7340+
version "1.5.1"
7341+
resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"
7342+
integrity sha512-LwZrotdHOo12nQuZlHEmtuXdqGoOD0OhaxopaNFxWzInpEgaLWoVuAMbTzixuosCx2nEG58ngzW3vxdWoxIgdg==
7343+
73397344
resolve-cwd@^2.0.0:
73407345
version "2.0.0"
73417346
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a"
@@ -8624,6 +8629,13 @@ url@^0.11.0:
86248629
punycode "1.3.2"
86258630
querystring "0.2.0"
86268631

8632+
use-fit-text@^2.4.0:
8633+
version "2.4.0"
8634+
resolved "https://registry.yarnpkg.com/use-fit-text/-/use-fit-text-2.4.0.tgz#d3d1cd72f6d29cfb2233ec0e0b38c6f25d319f67"
8635+
integrity sha512-Iy4LMrXcdxWlyZ5phntMpJMgyXGB1p3tV73y2r0QrZ6f/thPh+/QU3ie6RCXmjF8tHMs20FKMPskXeDYIla/Ww==
8636+
dependencies:
8637+
resize-observer-polyfill "^1.5.1"
8638+
86278639
use-isomorphic-layout-effect@^1.1.1:
86288640
version "1.1.2"
86298641
resolved "https://registry.yarnpkg.com/use-isomorphic-layout-effect/-/use-isomorphic-layout-effect-1.1.2.tgz#497cefb13d863d687b08477d9e5a164ad8c1a6fb"

0 commit comments

Comments
 (0)