-
Notifications
You must be signed in to change notification settings - Fork 3
Smart Textarea: Add new component #554
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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,23 @@ | ||
| <div | ||
| class="oss-smart-text-area-container {{if @hasError ' oss-smart-text-area-container--errored'}}" | ||
| {{did-insert this.registerElement}} | ||
| {{did-update this.handleUpdate @loading}} | ||
| ...attributes | ||
| > | ||
| <div class="fx-row"> | ||
| {{#if @loading}} | ||
| <div class="upf-input loading-placeholder fx-row fx-xalign-center"> | ||
| <pre class="smart_text_animated">{{or @value @placeholder}}</pre> | ||
| </div> | ||
| {{/if}} | ||
| <Textarea | ||
| @value={{@value}} | ||
| placeholder={{@placeholder}} | ||
| disabled={{@disabled}} | ||
| rows={{this.rows}} | ||
| class="oss-textarea {{this.computedClass}}" | ||
| {{on "keyup" (fn this._onChange @value)}} | ||
| /> | ||
| </div> | ||
|
|
||
| </div> |
This file contains hidden or 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,121 @@ | ||
| import { hbs } from 'ember-cli-htmlbars'; | ||
| import { action } from '@storybook/addon-actions'; | ||
|
|
||
| const ResizeTypes = ['horizontal', 'vertical', 'none', null]; | ||
|
|
||
| export default { | ||
| title: 'Components/OSS::Smart::TextArea', | ||
| component: 'smart text-area', | ||
| argTypes: { | ||
| value: { | ||
| description: 'Value of the textarea', | ||
| table: { | ||
| type: { | ||
| summary: 'string' | ||
| }, | ||
| defaultValue: { summary: 'undefined' } | ||
| }, | ||
| control: { type: 'text' } | ||
| }, | ||
| rows: { | ||
| description: 'Number of rows dispayed in the textarea', | ||
| table: { | ||
| type: { | ||
| summary: 'number' | ||
| }, | ||
| defaultValue: { summary: 2 } | ||
| }, | ||
| control: { type: 'number' } | ||
| }, | ||
| resize: { | ||
| description: 'Define direction in which textarea can be resized (By default the resize is set to Both)', | ||
| table: { | ||
| type: { | ||
| summary: ResizeTypes.join('|') | ||
| }, | ||
| defaultValue: { summary: 'both' } | ||
| }, | ||
| options: ResizeTypes, | ||
| control: { type: 'select' } | ||
| }, | ||
| disabled: { | ||
| description: 'Disable the default textarea', | ||
| table: { | ||
| type: { | ||
| summary: 'boolean' | ||
| }, | ||
| defaultValue: { summary: false } | ||
| }, | ||
| control: { type: 'boolean' } | ||
| }, | ||
| placeholder: { | ||
| description: 'Placeholder of the textarea', | ||
| table: { | ||
| type: { | ||
| summary: 'string' | ||
| }, | ||
| defaultValue: { summary: 'undefined' } | ||
| }, | ||
| control: { type: 'text' } | ||
| }, | ||
| loading: { | ||
| description: 'Indicates if the textarea is in a loading state', | ||
| table: { | ||
| type: { | ||
| summary: 'boolean' | ||
| }, | ||
| defaultValue: { summary: false } | ||
| }, | ||
| control: { type: 'boolean' } | ||
| }, | ||
| hasError: { | ||
| description: 'Indicates if the textarea has an error', | ||
| table: { | ||
| type: { | ||
| summary: 'boolean' | ||
| }, | ||
| defaultValue: { summary: false } | ||
| }, | ||
| control: { type: 'boolean' } | ||
| }, | ||
| onChange: { | ||
| description: 'Method called every time the textarea is updated', | ||
| table: { | ||
| category: 'Actions', | ||
| type: { | ||
| summary: 'onChange(value: string): void' | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| component: 'The OSS version of the textarea component.' | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| const defaultArgs = { | ||
| value: 'John', | ||
| rows: 2, | ||
| resize: null, | ||
| disabled: false, | ||
| placeholder: 'this is the placeholder', | ||
| hasError: false, | ||
| loading: false, | ||
| onChange: action('onChange') | ||
| }; | ||
|
|
||
| const DefaultUsageTemplate = (args) => ({ | ||
| template: hbs` | ||
| <OSS::Smart::TextArea @value={{this.value}} @disabled={{this.disabled}} @placeholder={{this.placeholder}} | ||
| @hasError={{this.hasError}} @onChange={{this.onChange}} @rows={{this.rows}} | ||
| @resize={{this.resize}} @loading={{this.loading}}/> | ||
| `, | ||
| context: args | ||
| }); | ||
|
|
||
| export const BasicUsage = DefaultUsageTemplate.bind({}); | ||
| BasicUsage.args = defaultArgs; |
This file contains hidden or 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,43 @@ | ||
| import { action } from '@ember/object'; | ||
| import { isEmpty } from '@ember/utils'; | ||
| import { tracked } from '@glimmer/tracking'; | ||
| import { runSmartGradientAnimation } from '@upfluence/oss-components/utils/run-smart-gradient-animation'; | ||
| import type { OSSTextAreaArgs, textAreaResizeOptions } from '../text-area'; | ||
| import OSSTextArea from '../text-area'; | ||
|
|
||
| interface OSSSmartImmersiveInputComponentSignature extends OSSTextAreaArgs { | ||
| value: string; | ||
| loading: boolean; | ||
| hasError?: boolean; | ||
| } | ||
|
|
||
| export default class OSSSmartTextareaComponent extends OSSTextArea<OSSSmartImmersiveInputComponentSignature> { | ||
| @tracked declare element: HTMLElement; | ||
| @tracked declare textAreaElement: HTMLTextAreaElement; | ||
|
|
||
| @action | ||
| handleUpdate(): void { | ||
| if (!this.args.loading && !isEmpty(this.args.value)) { | ||
| runSmartGradientAnimation(this.element); | ||
| } | ||
| } | ||
|
|
||
| @action | ||
| registerElement(element: HTMLElement): void { | ||
| this.element = element; | ||
| } | ||
|
|
||
| get resize(): textAreaResizeOptions | undefined { | ||
| return this.args.resize ?? 'none'; | ||
| } | ||
|
|
||
| get computedClass(): string { | ||
| let computedClass = super.computedClass; | ||
|
|
||
| if (this.args.loading) { | ||
| computedClass += ' oss-textarea--loading'; | ||
| } | ||
|
|
||
| return computedClass; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 @@ | ||
| export { default } from '@upfluence/oss-components/components/o-s-s/smart/text-area'; |
This file contains hidden or 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,51 @@ | ||
| .oss-smart-text-area-container { | ||
| .oss-textarea-container; | ||
| flex: 1; | ||
|
|
||
| > div { | ||
| position: relative; | ||
| } | ||
|
|
||
| .loading-placeholder { | ||
| position: absolute; | ||
| height: 100%; | ||
| width: 100%; | ||
| pointer-events: none; | ||
| display: flex; | ||
| align-items: flex-start; | ||
| flex-direction: column; | ||
| } | ||
|
|
||
| .smart_text_animated { | ||
| background: var(--color-gray-400); | ||
| background: linear-gradient( | ||
| 130deg, | ||
| var(--color-gray-400) 18%, | ||
| var(--color-gray-300) 25%, | ||
| rgba(250, 198, 255, 1) 56%, | ||
| var(--color-primary-100) 62%, | ||
| var(--color-white) 66%, | ||
| rgba(250, 198, 255, 0.58) 68%, | ||
| var(--color-gray-300) 73%, | ||
| var(--color-gray-400) 85% | ||
| ); | ||
| -webkit-background-clip: text; | ||
| background-clip: text; | ||
| color: transparent; | ||
| animation: smart_loading_text_animation 3.5s ease-in-out infinite; | ||
| background-size: 600% 100%; | ||
| padding: var(--spacing-px-6) 0px; | ||
|
|
||
| border: 0; | ||
| font-family: var(--font-family-stack); | ||
| .font-size-sm; | ||
| } | ||
|
|
||
| .oss-textarea { | ||
| transition: all 0s; | ||
| } | ||
|
|
||
| .oss-textarea--loading { | ||
| visibility: hidden; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -59,6 +59,8 @@ export default class Smart extends Controller { | |
| ]; | ||
| @tracked smartTags: { value: string; type: TagType }[] = []; | ||
| @tracked inputValue: string = ''; | ||
| @tracked textAreaValue: string = ''; | ||
| @tracked multilinePlaceholder: string = 'Small placeholder\nwith multiple\nlines'; | ||
|
|
||
| constructor() { | ||
| super(...arguments); | ||
|
|
@@ -190,6 +192,12 @@ export default class Smart extends Controller { | |
| return ''; | ||
| } | ||
|
|
||
| @action | ||
| onTextAreaChange(value: string): void { | ||
| console.log('Text area value changed:', value); | ||
|
Contributor
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. forgotten log
Contributor
Author
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. It's in dummy app :) |
||
| this.textAreaValue = value; | ||
| } | ||
|
|
||
| @action | ||
| fakeLoadData(): void { | ||
| this.loading = true; | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
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.
🥷 Remove span strange escape, which lead to unconsistent behavior between classic & loading state