-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement basic component API #14
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
4ec94bf
Add form component stub, setup Glint in test-app
simonihmig ea808d8
Add form test
simonihmig c1d3f69
form.field contextual component
simonihmig 0d53e2c
field.label contextual component
simonihmig 12a2eac
field.input contextual component
simonihmig 3283734
Fix type linting in tests
simonihmig 9daa0da
Support only Ember 4.8+
simonihmig 62f5fbd
Bring back Ember 4.4 support
simonihmig c523a90
Use native unique-id helper
simonihmig bed86e3
Remove classic scenario
simonihmig 3e93824
Use ensure-safe-component for strict Embroider compatibility
simonihmig 07edccb
Add ensure-safe-component Glint type
simonihmig 9b3eafe
Fix Glint errors
simonihmig 9278915
Pass data down
simonihmig ed1f6c1
Fix Embroider tests
simonihmig 38718aa
Pass value as string to input, fixes Glint
simonihmig b478d4d
Switch test-app to template-imports
simonihmig 1f5cadd
Add prettier-plugin-ember-template-tag
simonihmig 760fe2d
Add reactivity test
simonihmig 87f43ae
submit handler
simonihmig 865c834
yield value
simonihmig 0ba351f
yield field id
simonihmig 0f3c84d
yield setValue
simonihmig 81979df
Fix broken Glint declarations by rolling back public entrypoint changes
simonihmig a418ef6
Fix Glint types
simonihmig b63d5d2
Fix ESLint issues
simonihmig 19729e7
Disable no-implicit-this template-lint rule
simonihmig 093ad97
Tweak `@data` types, add Glint tests
simonihmig eaee023
Update ember-sinon-qunit, cleanup
simonihmig c094820
Tweak test message
simonihmig e77cba1
Add comment to VSCode prettier workaround
simonihmig cb2b675
Use `@nullvoxpopuli/eslint-configs` for addon
simonihmig 089fce2
Update to stable Ember 4.10.0
simonihmig 568199c
Try running Embroider tests with 1.x
simonihmig 8cc04a0
Remove ember-source from addon's devDependencies to "fix" Embroider
simonihmig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
plugins: ['prettier-plugin-ember-template-tag'], | ||
singleQuote: true, | ||
templateSingleQuote: false, | ||
}; |
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,37 +1,26 @@ | ||
ember-headless-form | ||
============================================================================== | ||
# ember-headless-form | ||
|
||
[Short description of the addon.] | ||
|
||
## Compatibility | ||
|
||
Compatibility | ||
------------------------------------------------------------------------------ | ||
- Ember.js v4.8 or above | ||
- Embroider or ember-auto-import v2 | ||
|
||
* Ember.js v3.28 or above | ||
* Embroider or ember-auto-import v2 | ||
|
||
|
||
Installation | ||
------------------------------------------------------------------------------ | ||
## Installation | ||
|
||
``` | ||
ember install ember-headless-form | ||
``` | ||
|
||
|
||
Usage | ||
------------------------------------------------------------------------------ | ||
## Usage | ||
|
||
[Longer description of how to use the addon in apps.] | ||
|
||
|
||
Contributing | ||
------------------------------------------------------------------------------ | ||
## Contributing | ||
|
||
See the [Contributing](CONTRIBUTING.md) guide for details. | ||
|
||
|
||
License | ||
------------------------------------------------------------------------------ | ||
## License | ||
|
||
This project is licensed under the [MIT License](LICENSE.md). |
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,50 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
root: true, | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
}, | ||
plugins: ['ember'], | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:ember/recommended', | ||
'plugin:prettier/recommended', | ||
], | ||
env: { | ||
browser: true, | ||
}, | ||
rules: {}, | ||
overrides: [ | ||
// ts files | ||
{ | ||
files: ['**/*.ts'], | ||
extends: [ | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
], | ||
rules: { | ||
// Add any custom rules here | ||
}, | ||
}, | ||
// node files | ||
{ | ||
files: [ | ||
'./.eslintrc.js', | ||
'./.prettierrc.js', | ||
'./.template-lintrc.js', | ||
'./addon-main.js', | ||
], | ||
parserOptions: { | ||
sourceType: 'script', | ||
}, | ||
env: { | ||
browser: false, | ||
node: true, | ||
}, | ||
plugins: ['node'], | ||
extends: ['plugin:node/recommended'], | ||
}, | ||
], | ||
}; | ||
const { configs } = require('@nullvoxpopuli/eslint-configs'); | ||
|
||
// accommodates: JS, TS, App, and Addon | ||
module.exports = configs.ember(); |
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,4 +1,5 @@ | ||
'use strict'; | ||
|
||
const { addonV1Shim } = require('@embroider/addon-shim'); | ||
|
||
module.exports = addonV1Shim(__dirname); |
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
7 changes: 7 additions & 0 deletions
7
ember-headless-form/src/components/-private/control/input.hbs
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,7 @@ | ||
<input | ||
type={{@type}} | ||
value={{this.valueAsString}} | ||
id={{@fieldId}} | ||
...attributes | ||
{{on 'input' this.handleInput}} | ||
/> |
62 changes: 62 additions & 0 deletions
62
ember-headless-form/src/components/-private/control/input.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,62 @@ | ||
import Component from '@glimmer/component'; | ||
import { assert } from '@ember/debug'; | ||
import { action } from '@ember/object'; | ||
|
||
// Possible values for the input type, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types | ||
// for the sake ok completeness, we list all here, with some commented out that are better handled elsewhere, or not at all... | ||
export type InputType = | ||
simonihmig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | 'button' - not useful as a control component | ||
// | 'checkbox' - handled separately, for handling `checked` correctly and operating with true boolean values | ||
| 'color' | ||
| 'date' | ||
| 'datetime-local' | ||
| 'email' | ||
// | 'file' - would need special handling | ||
| 'hidden' | ||
// | 'image' - not useful as a control component | ||
| 'month' | ||
| 'number' | ||
| 'password' | ||
// | 'radio' - handled separately, for handling groups or radio buttons | ||
| 'range' | ||
// | 'reset' - would need special handling | ||
| 'search' | ||
// | 'submit' - not useful as a control component | ||
| 'tel' | ||
| 'text' | ||
| 'time' | ||
| 'url' | ||
| 'week'; | ||
|
||
export interface HeadlessFormControlInputComponentSignature<VALUE> { | ||
Element: HTMLInputElement; | ||
Args: { | ||
value: VALUE; | ||
type?: InputType; | ||
fieldId: string; | ||
setValue: (value: VALUE) => void; | ||
}; | ||
NullVoxPopuli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
export default class HeadlessFormControlInputComponent<VALUE> extends Component< | ||
HeadlessFormControlInputComponentSignature<VALUE> | ||
> { | ||
get type(): InputType { | ||
return this.args.type ?? 'text'; | ||
} | ||
|
||
get valueAsString(): string { | ||
assert( | ||
`input can only handle string values, but you passed ${typeof this.args | ||
.value}`, | ||
typeof this.args.value === 'string' | ||
); | ||
|
||
return this.args.value; | ||
} | ||
|
||
@action | ||
handleInput(e: Event | InputEvent): void { | ||
this.args.setValue((e.target as HTMLInputElement).value as VALUE); | ||
} | ||
} |
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,16 @@ | ||
{{#let (unique-id) (fn @set @name) as |uuid setValue|}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: how come these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what you mean here with |
||
{{yield | ||
(hash | ||
label=(component (ensure-safe-component this.LabelComponent) fieldId=uuid) | ||
input=(component | ||
(ensure-safe-component this.InputComponent) | ||
fieldId=uuid | ||
value=this.value | ||
setValue=setValue | ||
) | ||
value=this.value | ||
id=uuid | ||
setValue=setValue | ||
) | ||
}} | ||
{{/let}} |
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,53 @@ | ||
import Component from '@glimmer/component'; | ||
|
||
import InputComponent from './control/input'; | ||
import LabelComponent from './field/label'; | ||
|
||
import type { HeadlessFormData } from '../headless-form'; | ||
import type { | ||
HeadlessFormControlInputComponentSignature, | ||
} from './control/input'; | ||
import type { | ||
HeadlessFormFieldLabelComponentSignature, | ||
} from './field/label'; | ||
import type { ComponentLike,WithBoundArgs } from '@glint/template'; | ||
|
||
export interface HeadlessFormFieldComponentSignature< | ||
DATA extends HeadlessFormData, | ||
KEY extends keyof DATA = keyof DATA | ||
> { | ||
Args: { | ||
data: DATA; | ||
name: KEY; | ||
set: (key: KEY, value: DATA[KEY]) => void; | ||
}; | ||
Blocks: { | ||
default: [ | ||
{ | ||
label: WithBoundArgs<typeof LabelComponent, 'fieldId'>; | ||
input: WithBoundArgs< | ||
typeof InputComponent<DATA[KEY]>, | ||
'fieldId' | 'value' | 'setValue' | ||
>; | ||
value: DATA[KEY]; | ||
id: string; | ||
setValue: (value: DATA[KEY]) => void; | ||
} | ||
]; | ||
}; | ||
} | ||
|
||
export default class HeadlessFormFieldComponent< | ||
DATA extends HeadlessFormData, | ||
KEY extends keyof DATA = keyof DATA | ||
> extends Component<HeadlessFormFieldComponentSignature<DATA, KEY>> { | ||
LabelComponent: ComponentLike<HeadlessFormFieldLabelComponentSignature> = | ||
LabelComponent; | ||
InputComponent: ComponentLike< | ||
HeadlessFormControlInputComponentSignature<DATA[KEY]> | ||
> = InputComponent; | ||
|
||
get value(): DATA[KEY] { | ||
return this.args.data[this.args.name]; | ||
} | ||
} |
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,3 @@ | ||
<label for={{@fieldId}} ...attributes> | ||
{{yield}} | ||
</label> |
13 changes: 13 additions & 0 deletions
13
ember-headless-form/src/components/-private/field/label.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,13 @@ | ||
import templateOnlyComponent from '@ember/component/template-only'; | ||
|
||
export interface HeadlessFormFieldLabelComponentSignature { | ||
Element: HTMLLabelElement; | ||
Args: { | ||
fieldId: string; | ||
}; | ||
Blocks: { | ||
default: []; | ||
}; | ||
} | ||
|
||
export default templateOnlyComponent<HeadlessFormFieldLabelComponentSignature>(); |
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,11 @@ | ||
<form ...attributes {{on 'submit' this.onSubmit}}> | ||
{{yield | ||
(hash | ||
field=(component | ||
(ensure-safe-component this.FieldComponent) | ||
data=this.internalData | ||
set=this.set | ||
) | ||
) | ||
}} | ||
</form> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question, just curious: We aren't supporting 3.28 anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this is the very start of everything, so we never supported anything before! 😆
But you are right, we are starting by not supporting Ember 3.28, at least that's the outcome of some back and forth between Preston and me. But we can revisit this decision, if you think there is a good reason to still support Ember 3.28.
Having Ember 3.28 support is good for existing addons, as that supports apps that still have trouble upgrading to 4. And it's quite unfortunate if addons don't have this overlap, and maybe only the newer version of an addon supports Ember 4, but not Ember 3.28. In this way users are forces to upgrade Ember and the addon at the same time.
But none of this applies here, as this is a green field project, and we don't have any existing Ember 3.28 users, so we can just support what is reasonable for us I think...