-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(interface): separate main suggestion, rename suggestion list
- Loading branch information
1 parent
267163d
commit c146a1f
Showing
5 changed files
with
153 additions
and
113 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
src/client/interface/components/terminal/suggestion/MainSuggestion.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { BindingOrValue } from "@rbxts/pretty-react-hooks"; | ||
import Roact, { Binding } from "@rbxts/roact"; | ||
import { fonts } from "../../../constants/fonts"; | ||
import { palette } from "../../../constants/palette"; | ||
import { useRem } from "../../../hooks/useRem"; | ||
import { ArgumentSuggestion, Suggestion } from "../../../types"; | ||
import { Frame } from "../../interface/Frame"; | ||
import { Group } from "../../interface/Group"; | ||
import { Padding } from "../../interface/Padding"; | ||
import { Text } from "../../interface/Text"; | ||
import { Badge } from "./Badge"; | ||
import { SuggestionSizes } from "./types"; | ||
import { highlightMatching } from "./util"; | ||
|
||
export interface MainSuggestionProps { | ||
suggestion?: Suggestion; | ||
argument: BindingOrValue<boolean>; | ||
currentText?: string; | ||
size: BindingOrValue<UDim2>; | ||
sizes: Binding<SuggestionSizes>; | ||
} | ||
|
||
export function MainSuggestion({ | ||
suggestion, | ||
currentText, | ||
size, | ||
sizes, | ||
argument, | ||
}: MainSuggestionProps) { | ||
const rem = useRem(); | ||
|
||
return ( | ||
<Frame | ||
size={size} | ||
backgroundColor={palette.crust} | ||
cornerRadius={new UDim(0, rem(0.5))} | ||
clipsDescendants={true} | ||
> | ||
<Padding key="padding" all={new UDim(0, rem(1))} /> | ||
|
||
<Group | ||
key="badges" | ||
anchorPoint={new Vector2(1, 0)} | ||
size={sizes.map((val) => | ||
UDim2.fromOffset(math.max(val.typeBadgeWidth, rem(7)), rem(4.5)), | ||
)} | ||
position={UDim2.fromScale(1, 0)} | ||
visible={argument} | ||
> | ||
<Badge | ||
key="optional-badge" | ||
size={new UDim2(1, 0, 0, rem(2))} | ||
color={ | ||
argument && | ||
suggestion !== undefined && | ||
(suggestion.main as ArgumentSuggestion).optional | ||
? palette.blue | ||
: palette.red | ||
} | ||
text={ | ||
argument && | ||
suggestion !== undefined && | ||
(suggestion.main as ArgumentSuggestion).optional | ||
? "Optional" | ||
: "Required" | ||
} | ||
textColor={palette.white} | ||
textSize={rem(1.5)} | ||
/> | ||
|
||
<Badge | ||
key="type-badge" | ||
size={new UDim2(1, 0, 0, rem(2))} | ||
position={UDim2.fromOffset(0, rem(2.5))} | ||
color={palette.surface0} | ||
text={ | ||
argument && suggestion !== undefined | ||
? (suggestion.main as ArgumentSuggestion).dataType | ||
: "" | ||
} | ||
textColor={palette.white} | ||
textSize={rem(1.5)} | ||
/> | ||
</Group> | ||
|
||
<Text | ||
key="title" | ||
size={sizes.map((val) => val.title)} | ||
text={ | ||
argument | ||
? suggestion?.main.title | ||
: highlightMatching(suggestion?.main.title, currentText) | ||
} | ||
textSize={rem(2)} | ||
textColor={palette.white} | ||
textXAlignment="Left" | ||
richText={true} | ||
font={fonts.inter.bold} | ||
/> | ||
|
||
<Text | ||
key="description" | ||
size={sizes.map((val) => val.description)} | ||
position={UDim2.fromOffset(0, rem(2))} | ||
text={suggestion?.main.description ?? ""} | ||
textSize={rem(1.5)} | ||
textColor={palette.white} | ||
textXAlignment="Left" | ||
textWrapped={true} | ||
richText={true} | ||
/> | ||
</Frame> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./SuggestionList"; | ||
export * from "./Suggestions"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface SuggestionSizes { | ||
title: UDim2; | ||
description: UDim2; | ||
typeBadgeWidth: number; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/client/interface/components/terminal/suggestion/util.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { palette } from "../../../constants/palette"; | ||
import { toHex } from "../../../util/color"; | ||
|
||
const HIGHLIGHT_PREFIX = `<font color="${toHex(palette.blue)}">`; | ||
|
||
export function highlightMatching(text?: string, terminalText?: string) { | ||
if (text === undefined) return ""; | ||
if (terminalText === undefined) return text; | ||
|
||
const subText = text.sub(0, terminalText.size()); | ||
if (terminalText.lower() !== subText.lower()) { | ||
return text; | ||
} | ||
|
||
const unhighlightedText = text.sub(terminalText.size() + 1); | ||
return `${HIGHLIGHT_PREFIX}${subText}</font>${unhighlightedText}`; | ||
} |