Skip to content

Commit

Permalink
fix some style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mullenpaul committed Jan 20, 2024
1 parent 0105968 commit 0016ed5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 38 deletions.
2 changes: 1 addition & 1 deletion tgui/packages/tgui/components/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class ButtonInput extends Component {
className="NumberInput__input"
style={{
'display': !this.state.inInput ? 'none' : undefined,
'text-align': 'left',
'textAlign': 'left',
}}
onBlur={(e) => {
if (!this.state.inInput) {
Expand Down
33 changes: 18 additions & 15 deletions tgui/packages/tgui/components/NumberInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/

import { clamp } from 'common/math';
import { classes, pureComponentHooks } from 'common/react';
import { classes } from 'common/react';
import { Component, createRef } from 'react';

import { AnimatedNumber } from './AnimatedNumber';
import { Box } from './Box';

Expand Down Expand Up @@ -165,14 +166,15 @@ export class NumberInput extends Component {
displayValue = intermediateValue;
}

// prettier-ignore
const contentElement = (
<div className="NumberInput__content" unselectable={Byond.IS_LTE_IE8}>
{
(animated && !dragging && !suppressingFlicker) ?
(<AnimatedNumber value={displayValue} format={format} />) :
(format ? format(displayValue) : displayValue)
}
<div className="NumberInput__content">
{animated && !dragging && !suppressingFlicker ? (
<AnimatedNumber value={displayValue} format={format} />
) : format ? (
format(displayValue)
) : (
displayValue
)}

{unit ? ' ' + unit : ''}
</div>
Expand All @@ -194,10 +196,12 @@ export class NumberInput extends Component {
<div
className="NumberInput__bar"
style={{
// prettier-ignore
height: clamp(
(displayValue - minValue) / (maxValue - minValue) * 100,
0, 100) + '%',
height:
clamp(
((displayValue - minValue) / (maxValue - minValue)) * 100,
0,
100
) + '%',
}}
/>
</div>
Expand All @@ -208,8 +212,8 @@ export class NumberInput extends Component {
style={{
display: !editing ? 'none' : undefined,
height: height,
'line-height': lineHeight,
'font-size': fontSize,
lineHeight: lineHeight,
fontSize: fontSize,
}}
onBlur={(e) => {
if (!editing) {
Expand Down Expand Up @@ -274,7 +278,6 @@ export class NumberInput extends Component {
}
}

NumberInput.defaultHooks = pureComponentHooks;
NumberInput.defaultProps = {
minValue: -Infinity,
maxValue: +Infinity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,31 @@
* @license MIT
*/

import { clamp01, scale, keyOfMatchingRange, toFixed } from 'common/math';
import { classes, pureComponentHooks } from 'common/react';
import { computeBoxClassName, computeBoxProps } from './Box';
import { clamp01, keyOfMatchingRange, scale, toFixed } from 'common/math';
import { classes } from 'common/react';
import { PropsWithChildren } from 'react';

import { CSS_COLORS } from '../constants';
import { BoxProps, computeBoxClassName, computeBoxProps } from './Box';

type Props = {
readonly value: number;
} & Partial<{
backgroundColor: string;
className: string;
color: string;
height: string | number;
maxValue: number;
minValue: number;
ranges: Record<string, [number, number]>;
style: Partial<HTMLDivElement['style']>;
title: string;
width: string | number;
}> &
Partial<BoxProps> &
PropsWithChildren;

export const ProgressBar = (props) => {
export const ProgressBar = (props: Props) => {
const {
className,
value,
Expand All @@ -22,32 +41,28 @@ export const ProgressBar = (props) => {
} = props;
const scaledValue = scale(value, minValue, maxValue);
const hasContent = children !== undefined;
// prettier-ignore
const effectiveColor = color
|| keyOfMatchingRange(value, ranges)
|| 'default';

const effectiveColor =
color || keyOfMatchingRange(value, ranges) || 'default';

// We permit colors to be in hex format, rgb()/rgba() format,
// a name for a color-<name> class, or a base CSS class.
const outerProps = computeBoxProps(rest);
// prettier-ignore
const outerClasses = [
'ProgressBar',
className,
computeBoxClassName(rest),
];

const outerClasses = ['ProgressBar', className, computeBoxClassName(rest)];
const fillStyles = {
'width': clamp01(scaledValue) * 100 + '%',
width: clamp01(scaledValue) * 100 + '%',
};
if (CSS_COLORS.includes(effectiveColor) || effectiveColor === 'default') {
if (
CSS_COLORS.includes(effectiveColor as any) ||
effectiveColor === 'default'
) {
// If the color is a color-<name> class, just use that.
outerClasses.push('ProgressBar--color--' + effectiveColor);
} else {
// Otherwise, set styles directly.
// prettier-ignore
outerProps.style = (outerProps.style || "")
+ `border-color: ${effectiveColor};`;
fillStyles['background-color'] = effectiveColor;
outerProps.style = { ...outerProps.style, borderColor: effectiveColor };
fillStyles['backgroundColor'] = effectiveColor;
}

return (
Expand All @@ -62,5 +77,3 @@ export const ProgressBar = (props) => {
</div>
);
};

ProgressBar.defaultHooks = pureComponentHooks;

0 comments on commit 0016ed5

Please sign in to comment.