-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9645ff
commit 06e7812
Showing
8 changed files
with
159 additions
and
55 deletions.
There are no files selected for viewing
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,84 @@ | ||
import Component from "ui/Component" | ||
import type { InputExtensions } from "ui/component/core/ext/Input" | ||
import Input from "ui/component/core/ext/Input" | ||
import type { PopoverInitialiser } from "ui/component/core/Popover" | ||
import type { TextInputExtensions } from "ui/component/core/TextInput" | ||
import TextInput from "ui/component/core/TextInput" | ||
|
||
interface VanityInputExtensions { | ||
readonly input: TextInput | ||
} | ||
|
||
interface VanityInput extends TextInput, VanityInputExtensions { } | ||
|
||
const VanityInput = Object.assign( | ||
Component.Builder((component): VanityInput => { | ||
const input = TextInput() | ||
.style("vanity-input-input") | ||
.filter(filterVanity) | ||
.appendTo(component) | ||
|
||
return component.and(Input) | ||
.style("vanity-input") | ||
.append(Component() | ||
.style("vanity-input-prefix") | ||
.text.set("@")) | ||
.extend<VanityInputExtensions & TextInputExtensions & InputExtensions>(component => ({ | ||
// vanity input | ||
input, | ||
|
||
// input | ||
required: input.required, | ||
hint: input.hint.rehost(component), | ||
maxLength: input.maxLength, | ||
length: input.length, | ||
setMaxLength (maxLength?: number) { | ||
input.setMaxLength(maxLength) | ||
return component | ||
}, | ||
setRequired (required?: boolean) { | ||
input.setRequired(required) | ||
return component | ||
}, | ||
setLabel (label) { | ||
input.setLabel(label) | ||
return component | ||
}, | ||
tweakPopover (initialiser: PopoverInitialiser<typeof component>) { | ||
input.tweakPopover(initialiser as never) | ||
return component | ||
}, | ||
|
||
// text input | ||
state: input.state, | ||
get value () { return input.value }, | ||
set value (value: string) { input.value = value }, | ||
default: input.default.rehost(component), | ||
placeholder: input.placeholder.rehost(component), | ||
ignoreInputEvent (ignore = true) { | ||
input.ignoreInputEvent(ignore) | ||
return component | ||
}, | ||
filter (filter) { | ||
input.filter(filter) | ||
return component | ||
}, | ||
})) | ||
}), | ||
{ | ||
filter: filterVanity, | ||
} | ||
) | ||
|
||
export default VanityInput | ||
|
||
function filterVanity (vanity: string, textBefore = "", isFullText = true) { | ||
vanity = vanity.replace(/[\W_]+/g, "-") | ||
if (isFullText) | ||
vanity = vanity.replace(/^-|-$/g, "") | ||
|
||
if (textBefore.endsWith("-") && vanity.startsWith("-")) | ||
return vanity.slice(1) | ||
|
||
return vanity | ||
} |
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
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,3 +1,5 @@ | ||
$input-divider-border-colour: color-mix(in lch, $border-colour, transparent 90%) | ||
|
||
.input: | ||
|
||
&-popover: | ||
|
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.vanity-input: | ||
%grid | ||
%stack | ||
|
||
&-input: | ||
%stack-self | ||
%padding-left-4 | ||
; padding-left: calc($space-4 + $space-2) | ||
|
||
&-prefix: | ||
%stack-self | ||
%width-4 | ||
%grid | ||
%align-content-centre | ||
%justify-content-end | ||
%padding-right-1 | ||
%relative | ||
%margin-block-1 | ||
%border-box | ||
%no-pointer-events | ||
%opacity-50 | ||
top: -.06rem |
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