Skip to content

Commit

Permalink
feat(files): create folder-creation-form component
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed Jun 15, 2021
1 parent 286a5f8 commit 8e03fd8
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 116 deletions.
7 changes: 7 additions & 0 deletions src/components/specific/files/files-manager/FilesManager.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
}

.bimdata-card__content {
position: relative;
height: calc(100% - 35px - 26px);

display: grid;
Expand Down Expand Up @@ -55,6 +56,12 @@
height: 100%;
}
}

.files-manager__onboarding {
position: absolute;
width: 100%;
height: 100%;
}
}
}
}
5 changes: 4 additions & 1 deletion src/components/specific/files/files-manager/FilesManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@
</template>

<template v-else>
<FilesManagerOnboarding :project="project" />
<FilesManagerOnboarding
class="files-manager__onboarding"
:project="project"
/>
</template>
</template>
</BIMDataCard>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,6 @@
position: absolute;
top: calc(100% + #{$spacing-unit});
width: 260px;
padding: $spacing-unit;
background-color: $color-white;
@include box-shadow;

display: flex;
flex-wrap: wrap;

&__title {
width: 100%;
display: flex;
align-items: flex-end;
gap: $spacing-unit/2;
color: $color-primary;
}

&__input {
width: 100%;
margin: $spacing-unit * 2 0;
font-size: 1rem;
}

&__btn-cancel {
margin-left: auto;
}

&__btn-submit {
margin-left: $spacing-unit;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,36 @@
@click="toggle"
>
<BIMDataIcon name="addFolder" size="xs" />
<span>{{ $t("FolderCreationButton.createFolderButtonText") }}</span>
<span>{{ $t("FolderCreationButton.buttonText") }}</span>
</BIMDataButton>

<transition name="fade">
<div class="folder-creation-button__form" v-show="showCreationForm">
<div class="folder-creation-button__form__title">
<BIMDataIcon name="addFolder" size="xs" />
<span>{{ $t("FolderCreationButton.creationFormTitle") }}</span>
</div>
<BIMDataInput
ref="nameInput"
class="folder-creation-button__form__input"
:placeholder="$t('FolderCreationButton.nameInputPlaceholder')"
v-model="name"
:error="error"
:errorMessage="$t('FolderCreationButton.nameInputErrorMessage')"
@keyup.esc.stop="close"
@keyup.enter.stop="submit"
/>
<BIMDataButton
class="folder-creation-button__form__btn-cancel"
width="80px"
ghost
radius
@click="close"
>
{{ $t("FolderCreationButton.cancelButtonText") }}
</BIMDataButton>
<BIMDataButton
class="folder-creation-button__form__btn-submit"
width="80px"
color="primary"
fill
radius
@click="submit"
>
{{ $t("FolderCreationButton.submitButtonText") }}
</BIMDataButton>
</div>
<FolderCreationForm
v-if="showCreationForm"
class="folder-creation-button__form"
:project="project"
:folder="folder"
@close="close"
@success="close"
/>
</transition>
</div>
</template>

<script>
import { ref } from "vue";
import { useFiles } from "@/state/files";
// Components
import BIMDataButton from "@bimdata/design-system/dist/js/BIMDataComponents/vue3/BIMDataButton.js";
import BIMDataIcon from "@bimdata/design-system/dist/js/BIMDataComponents/vue3/BIMDataIcon.js";
import BIMDataInput from "@bimdata/design-system/dist/js/BIMDataComponents/vue3/BIMDataInput.js";
import FolderCreationForm from "@/components/specific/files/folder-creation-form/FolderCreationForm";
export default {
components: {
BIMDataButton,
BIMDataIcon,
BIMDataInput
BIMDataInput,
FolderCreationForm
},
props: {
width: {
Expand All @@ -81,52 +55,24 @@ export default {
required: true
},
folder: {
type: Object
type: Object,
required: true
}
},
setup(props) {
const { createFolder } = useFiles();
const nameInput = ref(null);
const name = ref("");
const error = ref(false);
const submit = async () => {
if (name.value) {
await createFolder(props.project, {
parentId: props.folder.id,
name: name.value
});
close();
} else {
nameInput.value.focus();
error.value = true;
}
};
setup() {
const showCreationForm = ref(false);
const close = () => {
name.value = "";
error.value = false;
showCreationForm.value = false;
};
const toggle = () => {
error.value = false;
showCreationForm.value = !showCreationForm.value;
if (showCreationForm.value) {
setTimeout(() => nameInput.value.focus(), 200);
}
};
return {
// References
error,
name,
nameInput,
showCreationForm,
// Methods
close,
submit,
toggle
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.folder-creation-form {
padding: $spacing-unit;
background-color: $color-white;

display: flex;
flex-wrap: wrap;

&__title {
width: 100%;
display: flex;
align-items: flex-end;
gap: $spacing-unit/2;
color: $color-primary;
}

&__input {
width: 100%;
margin: $spacing-unit * 2 0;
font-size: 1rem;
}

&__btn-cancel {
margin-left: auto;
}

&__btn-submit {
margin-left: $spacing-unit;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<template>
<div class="folder-creation-form">
<div class="folder-creation-form__title">
<BIMDataIcon name="addFolder" size="xs" />
<span>{{ $t("FolderCreationForm.creationFormTitle") }}</span>
</div>
<BIMDataInput
ref="nameInput"
class="folder-creation-form__input"
:placeholder="$t('FolderCreationForm.nameInputPlaceholder')"
v-model="name"
:error="error"
:errorMessage="$t('FolderCreationForm.nameInputErrorMessage')"
@keyup.esc.stop="close"
@keyup.enter.stop="submit"
/>
<BIMDataButton
class="folder-creation-form__btn-cancel"
width="80px"
ghost
radius
@click="close"
>
{{ $t("FolderCreationForm.cancelButtonText") }}
</BIMDataButton>
<BIMDataButton
class="folder-creation-form__btn-submit"
width="80px"
color="primary"
fill
radius
@click="submit"
>
{{ $t("FolderCreationForm.submitButtonText") }}
</BIMDataButton>
</div>
</template>

<script>
import { onMounted, ref } from "vue";
import { useFiles } from "@/state/files";
// Components
import BIMDataButton from "@bimdata/design-system/dist/js/BIMDataComponents/vue3/BIMDataButton.js";
import BIMDataIcon from "@bimdata/design-system/dist/js/BIMDataComponents/vue3/BIMDataIcon.js";
import BIMDataInput from "@bimdata/design-system/dist/js/BIMDataComponents/vue3/BIMDataInput.js";
export default {
components: {
BIMDataButton,
BIMDataIcon,
BIMDataInput
},
props: {
project: {
type: Object,
required: true
},
folder: {
type: Object,
required: true
}
},
emits: ["close", "success", "error"],
setup(props, { emit }) {
const { createFolder } = useFiles();
const nameInput = ref(null);
const name = ref("");
const error = ref(false);
const reset = () => {
name.value = "";
error.value = false;
};
const submit = async () => {
if (name.value) {
try {
await createFolder(props.project, {
parentId: props.folder.id,
name: name.value
});
reset();
emit("success");
} catch (error) {
emit("error", error);
}
} else {
nameInput.value.focus();
error.value = true;
}
};
const close = () => {
reset();
emit("close");
};
onMounted(() => {
setTimeout(() => nameInput.value.focus(), 200);
});
return {
// References
error,
name,
nameInput,
// Methods
close,
submit
};
}
}
</script>

<style scoped lang="scss" src="./FolderCreationForm.scss"></style>
Loading

0 comments on commit 8e03fd8

Please sign in to comment.