Skip to content

Commit

Permalink
enhancement: update input component dynamic text alignment (janhq#2712)
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur authored Apr 15, 2024
1 parent 09fcdac commit 1619478
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/src/types/setting/settingComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type InputComponentProps = {
placeholder: string
value: string
type?: InputType
textAlign?: 'left' | 'right'
}

export type SliderComponentProps = {
Expand Down
3 changes: 2 additions & 1 deletion extensions/monitoring-extension/resources/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"controllerType": "input",
"controllerProps": {
"value": "120000",
"placeholder": "Interval in milliseconds. E.g. 120000"
"placeholder": "Interval in milliseconds. E.g. 120000",
"textAlign": "right"
}
}
]
12 changes: 9 additions & 3 deletions uikit/src/input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import { forwardRef } from 'react'
import { twMerge } from 'tailwind-merge'

export interface InputProps
extends React.InputHTMLAttributes<HTMLInputElement> {}
extends React.InputHTMLAttributes<HTMLInputElement> {
textAlign?: 'left' | 'right'
}

const Input = forwardRef<HTMLInputElement, InputProps>(
({ className, type, ...props }, ref) => {
({ className, type, textAlign, ...props }, ref) => {
return (
<input
type={type}
className={twMerge('input', className)}
className={twMerge(
'input',
className,
textAlign === 'right' && 'text-right'
)}
ref={ref}
{...props}
/>
Expand Down
3 changes: 3 additions & 0 deletions uikit/src/input/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
@apply disabled:text-muted-foreground disabled:cursor-not-allowed disabled:bg-zinc-100 disabled:dark:bg-zinc-800 disabled:dark:text-zinc-600;
@apply focus-within:outline-none focus-visible:outline-0 focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-1;
@apply file:border-0 file:bg-transparent file:font-medium;
&.text-right {
text-align: right;
}
}
1 change: 1 addition & 0 deletions web/containers/SliderRightPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const SliderRightPanel: React.FC<Props> = ({
min={min}
max={max}
value={String(value)}
textAlign="right"
disabled={!enabled}
onBlur={(e) => {
if (Number(e.target.value) > Number(max)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const SettingDetailTextInputItem: React.FC<Props> = ({
settingProps,
onValueChanged,
}) => {
const { value, type, placeholder } =
const { value, type, placeholder, textAlign } =
settingProps.controllerProps as InputComponentProps

const description = marked.parse(settingProps.description ?? '', {
Expand All @@ -43,6 +43,7 @@ const SettingDetailTextInputItem: React.FC<Props> = ({
<Input
placeholder={placeholder}
type={type}
textAlign={textAlign}
value={value}
className="ml-4 w-[360px]"
onChange={(e) => onValueChanged?.(e.target.value)}
Expand Down

0 comments on commit 1619478

Please sign in to comment.