-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(U) add support for Glimmer TypeScript, #828 part 2 of 2
- Loading branch information
Showing
5 changed files
with
204 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,150 @@ | ||
{{! partial of | ||
https://raw.githubusercontent.com/josemarluedke/frontile/a9680f2681a8b1193feba0fdc27871566bcde120/packages/forms/src/components/input.gts | ||
}} | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
import { on } from '@ember/modifier'; | ||
import { | ||
useStyles, | ||
type InputSlots, | ||
type InputVariants, | ||
type SlotsToClasses | ||
} from '@frontile/theme'; | ||
import { FormControl, type FormControlSharedArgs } from './form-control'; | ||
import { triggerFormInputEvent } from '../utils'; | ||
import { ref } from '@frontile/utilities'; | ||
import { CloseButton } from '@frontile/buttons'; | ||
|
||
interface Args extends FormControlSharedArgs { | ||
type?: string; | ||
value?: string; | ||
name?: string; | ||
size?: InputVariants['size']; | ||
classes?: SlotsToClasses<InputSlots>; | ||
|
||
/** | ||
* Whether to include a clear button | ||
*/ | ||
isClearable?: boolean; | ||
|
||
/** | ||
* Controls pointer-events property of startContent. | ||
* If you want to pass the click event to the input, set it to `none`. | ||
* | ||
* @defaultValue 'auto' | ||
*/ | ||
startContentPointerEvents?: 'none' | 'auto'; | ||
|
||
/** | ||
* Controls pointer-events property of endContent. | ||
* If you want to pass the click event to the input, set it to `none`. | ||
* | ||
* @defaultValue 'auto' | ||
*/ | ||
endContentPointerEvents?: 'none' | 'auto'; | ||
|
||
/** | ||
* Callback when oninput is triggered | ||
*/ | ||
onInput?: (value: string, event?: InputEvent) => void; | ||
|
||
/** | ||
* Callback when onchange is triggered | ||
*/ | ||
onChange?: (value: string, event?: InputEvent) => void; | ||
} | ||
|
||
interface InputSignature { | ||
Args: Args; | ||
Blocks: { | ||
startContent: []; | ||
endContent: []; | ||
}; | ||
Element: HTMLInputElement; | ||
} | ||
|
||
function or(arg1: unknown, arg2: unknown): boolean { | ||
return !!(arg1 || arg2); | ||
} | ||
|
||
class Input extends Component<InputSignature> { | ||
@tracked uncontrolledValue: string = ''; | ||
|
||
inputRef = ref<HTMLInputElement>(); | ||
|
||
if (this.isControlled) { | ||
this.args.onInput?.(value, event as InputEvent); | ||
} else { | ||
this.uncontrolledValue = value; | ||
} | ||
} | ||
|
||
@action handleOnChange(event: Event): void { | ||
const value = (event.target as HTMLInputElement).value; | ||
|
||
if (this.isControlled) { | ||
this.args.onChange?.(value, event as InputEvent); | ||
} else { | ||
this.uncontrolledValue = value; | ||
} | ||
} | ||
|
||
this.inputRef.element?.focus(); | ||
triggerFormInputEvent(this.inputRef.element); | ||
} | ||
|
||
<template> | ||
<FormControl | ||
@size={{@size}} | ||
@label={{@label}} | ||
@isRequired={{@isRequired}} | ||
@description={{@description}} | ||
@errors={{@errors}} | ||
@isInvalid={{@isInvalid}} | ||
@class={{this.classes.base class=@classes.base}} | ||
as |c| | ||
> | ||
<div class={{this.classes.innerContainer class=@classes.innerContainer}}> | ||
{{#if (has-block "startContent")}} | ||
<div | ||
data-test-id="input-start-content" | ||
class={{this.classes.startContent | ||
class=@classes.startContent | ||
startContentPointerEvents=(if | ||
@startContentPointerEvents @startContentPointerEvents "auto" | ||
) | ||
}} | ||
> | ||
{{yield to="startContent"}} | ||
</div> | ||
{{/if}} | ||
<input | ||
{{this.inputRef.setup}} | ||
{{on "input" this.handleOnInput}} | ||
{{on "change" this.handleOnChange}} | ||
id={{c.id}} | ||
}} | ||
data-component="input" | ||
aria-invalid={{if c.isInvalid "true"}} | ||
aria-describedby={{c.describedBy @description c.isInvalid}} | ||
...attributes | ||
/> | ||
{{#if (or (has-block "endContent") this.isClearable)}} | ||
<div | ||
> | ||
{{yield to="endContent"}} | ||
|
||
{{#if this.isClearable}} | ||
<CloseButton | ||
/> | ||
{{/if}} | ||
</div> | ||
{{/if}} | ||
</div> | ||
</FormControl> | ||
</template> | ||
} | ||
|
||
export { Input, type InputSignature }; | ||
export default Input; |
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,21 @@ | ||
--- | ||
# github.com/AlDanial/cloc | ||
header : | ||
cloc_url : github.com/AlDanial/cloc | ||
cloc_version : 2.01 | ||
elapsed_seconds : 0.00317215919494629 | ||
n_files : 1 | ||
n_lines : 150 | ||
files_per_second : 315.242690717775 | ||
lines_per_second : 47286.4036076663 | ||
report_file : ../outputs/input.gts.yaml | ||
'Glimmer TypeScript' : | ||
nFiles: 1 | ||
blank: 17 | ||
comment: 24 | ||
code: 109 | ||
SUM: | ||
blank: 17 | ||
comment: 24 | ||
code: 109 | ||
nFiles: 1 |