-
Notifications
You must be signed in to change notification settings - Fork 0
feat(FoInputFile): First implementation #137
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
e399f79
feat(FoInputFile): First implementation
michaelcozzolino dea01fa
feat(InputFileDocs): First implementation
michaelcozzolino ed2c875
feat(FoInputFile): Add snapshots
michaelcozzolino 1486f29
feat(FoInputFile): Add snapshots
michaelcozzolino f25ad0c
feat(FoInputFile): Add snapshots
michaelcozzolino 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import type { ComponentName } from '@/Lib'; | ||
|
|
||
| export type FloatingLabelComponentName = Extract<ComponentName, 'FoInputText' | 'FoSelect' | 'FoTextarea'>; | ||
| // todo: there is a mismatch between configurable and floating, this should be checked | ||
| export type FloatingLabelComponentName = Extract<ComponentName, 'FoInputFile' | 'FoInputText' | 'FoSelect' | 'FoTextarea'>; |
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
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
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,11 @@ | ||
| import type { Disableable, MaybeStringId, Sizable, Validity } from '@/Lib'; | ||
| import type { LabelType, WithConfigurableHelperText, WithConfigurableInputLabel } from '@/UI/Components'; | ||
|
|
||
| export type InputFileLabelType = Extract<LabelType, 'text' | 'floating'>; | ||
|
|
||
| export type InputFileProps = MaybeStringId | ||
| & Disableable | ||
| & Sizable | ||
| & WithConfigurableInputLabel<InputFileLabelType> | ||
| & Validity | ||
| & WithConfigurableHelperText; | ||
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 * from '@/UI/Forms/InputFile/Types/InputFile'; |
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,33 @@ | ||
| <template> | ||
| <FoInputFiles v-bind="props" | ||
| :multiple="false" | ||
| @upload:files="uploadFile" | ||
| /> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import type { InputFileProps } from '@/UI/Forms'; | ||
| import { FoInputFiles } from '@/UI/Forms'; | ||
|
|
||
| const props = withDefaults(defineProps<InputFileProps>(), { | ||
| isValid: undefined, | ||
| }); | ||
|
|
||
| const emit = defineEmits<{ | ||
| (e: 'upload:file', file: File): void; | ||
| }>(); | ||
|
|
||
| function uploadFile(files: FileList): void { | ||
| const file = files.item(0); | ||
|
|
||
| if (file === null) { | ||
| throw new Error('Received an upload file event but no file has been uploaded.'); | ||
| } | ||
|
|
||
| if (files.length > 1) { | ||
| throw new Error('Received an upload file event with multiple files.'); | ||
| } | ||
|
|
||
| emit('upload:file', file); | ||
| } | ||
| </script> |
102 changes: 102 additions & 0 deletions
102
packages/core/src/UI/Forms/InputFile/UI/FoInputFiles.vue
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,102 @@ | ||
| <template> | ||
| <div :class="floatingLabelClass" | ||
| :style="$attrs.style as StyleValue" | ||
| > | ||
| <FoLabel v-if="defaultLabel?.type === 'text'" | ||
| :for="id" | ||
| :component-name="componentName" | ||
| type="text" | ||
| :is-hidden="defaultLabel.isHidden" | ||
| > | ||
| {{ defaultLabel.text }} | ||
| </FoLabel> | ||
|
|
||
| <input :id="id" | ||
| type="file" | ||
| class="input" | ||
| :class="[sizeClass, validityClass]" | ||
| :disabled="isDisabled" | ||
| multiple | ||
| v-bind="reactiveOmit($attrs, 'style')" | ||
| @change="change" | ||
| > | ||
|
|
||
| <FoLabel v-if="defaultLabel?.type === 'floating'" | ||
| :for="id" | ||
| :component-name="componentName" | ||
| type="floating" | ||
| :is-hidden="defaultLabel.isHidden" | ||
| > | ||
| {{ defaultLabel.text }} | ||
| </FoLabel> | ||
|
|
||
| <FoHelperText v-if="inputFileHelperText !== undefined" | ||
| :position="inputFileHelperText.position" | ||
| > | ||
| {{ inputFileHelperText.text }} | ||
| </FoHelperText> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import type { ComponentName } from '@/Lib'; | ||
| import type { InputFileProps } from '@/UI/Forms/InputFile'; | ||
| import type { StyleValue } from 'vue'; | ||
| import { useFlyonUIVueAppConfig } from '@/Lib'; | ||
| import { useFloatingLabel } from '@/Lib/UseFloatingLabel/Internal'; | ||
| import { useElementId } from '@/Lib/UseIdentifiable/Internal'; | ||
| import { useSize } from '@/Lib/UseSize/Internal'; | ||
| import { useValidity } from '@/Lib/UseValidity/Internal'; | ||
| import { FoHelperText, usePositionableHelperText } from '@/UI/Components/HelperText/Internal'; | ||
| import { FoLabel, useLabel } from '@/UI/Components/Label/Internal'; | ||
| import { reactiveOmit } from '@vueuse/core'; | ||
|
|
||
| defineOptions({ | ||
| inheritAttrs: false, | ||
| }); | ||
|
|
||
| const props = withDefaults(defineProps<InputFileProps>(), { | ||
| isValid: undefined, | ||
| }); | ||
|
|
||
| const emit = defineEmits<{ | ||
| (e: 'upload:files', files: FileList): void; | ||
| }>(); | ||
|
|
||
| const componentName: ComponentName = 'FoInputFile'; | ||
| const { config } = useFlyonUIVueAppConfig(); | ||
|
|
||
| const id = useElementId(() => props.id); | ||
|
|
||
| const defaultLabel = useLabel( | ||
| config, | ||
| componentName, | ||
| () => props.label, | ||
| ); | ||
|
|
||
| const inputFileHelperText = usePositionableHelperText( | ||
| config, | ||
| componentName, | ||
| () => props.helperText, | ||
| ); | ||
|
|
||
| const [ | ||
| floatingLabelClass, | ||
| sizeClass, | ||
| validityClass, | ||
| ] = [ | ||
| useFloatingLabel(componentName, () => defaultLabel.value?.type), | ||
| useSize(config, componentName, () => props.size), | ||
| useValidity(() => props.isValid), | ||
| ]; | ||
|
|
||
| function change(event: Event): void { | ||
| const target = event.target; | ||
|
|
||
| if (target instanceof HTMLInputElement === false || target.files === null) { | ||
| throw new TypeError('The event does not come from an input element.'); | ||
| } | ||
|
|
||
| emit('upload:files', target.files); | ||
michaelcozzolino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| </script> | ||
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,2 @@ | ||
| export { default as FoInputFile } from '@/UI/Forms/InputFile/UI/FoInputFile.vue'; | ||
| export { default as FoInputFiles } from '@/UI/Forms/InputFile/UI/FoInputFiles.vue'; |
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,2 @@ | ||
| export * from '@/UI/Forms/InputFile/Types'; | ||
| export * from '@/UI/Forms/InputFile/UI'; |
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
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,41 @@ | ||
| # Input file | ||
|
|
||
| ### Default | ||
|
|
||
| <InputFileDocs section="default" /> | ||
|
|
||
| ### Labels | ||
|
|
||
| <InputFileDocs section="label" /> | ||
|
|
||
| ### Sizes | ||
|
|
||
| <InputFileDocs section="size" /> | ||
|
|
||
| ### Validation states | ||
|
|
||
| <InputFileDocs section="validation-state" /> | ||
michaelcozzolino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Illustrations | ||
|
|
||
| ### Disabled | ||
|
|
||
| <InputFileDocs section="disabled" /> | ||
|
|
||
| ### Helper text | ||
|
|
||
| <InputFileDocs section="helper-text" /> | ||
|
|
||
| ### Multiple files | ||
|
|
||
| <InputFileDocs section="multiple-files" /> | ||
|
|
||
| ## Api | ||
|
|
||
| ### Props | ||
|
|
||
| <InputFileDocs section="props" /> | ||
|
|
||
| ### Slots | ||
|
|
||
| <InputFileDocs section="slots" /> | ||
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,10 @@ | ||
| <template> | ||
| <FoInputFile @upload:file="file = $event" /> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { FoInputFile } from 'flyonui-vue'; | ||
| import { ref } from 'vue'; | ||
|
|
||
| const file = ref<File | null>(null); | ||
| </script> |
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,12 @@ | ||
| <template> | ||
| <FoInputFile is-disabled | ||
| @upload:file="file = $event" | ||
| /> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { FoInputFile } from 'flyonui-vue'; | ||
| import { ref } from 'vue'; | ||
|
|
||
| const file = ref<File | null>(null); | ||
| </script> |
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.
Uh oh!
There was an error while loading. Please reload this page.