This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
904 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<script setup lang="ts"> | ||
import type { GridWidget } from '@/types/grid' | ||
const { modal, closeModal } = useModal() | ||
const { formatMessage } = useIntl() | ||
const { tempGridLayout, selectedLayoutId } = storeToRefs(useGridStore()) | ||
const { addGrid, updateGrid } = useGrid() | ||
const INPUT_FOCUS_DELAY = 10 // small delay for focusing input after element render | ||
const DEFAULT_PROPERTIES = { | ||
title: '', | ||
} | ||
const inputValues = reactive(DEFAULT_PROPERTIES) | ||
const inputErrors = reactive({ | ||
title: '', | ||
}) | ||
const id = computed(() => modal?.data?.grid?.id) | ||
const canSubmit = ref(false) | ||
const isEdit = computed(() => !!id.value) | ||
const handleTitleChange = async (customEvent: CustomEvent) => { | ||
const event = customEvent.detail.event | ||
const input = event.target as HTMLInputElement | ||
inputErrors.title = '' | ||
if (!input.value) { | ||
inputErrors.title = formatMessage('errors_required') | ||
return | ||
} | ||
inputValues.title = input.value | ||
} | ||
const handleCancel = () => { | ||
closeModal() | ||
} | ||
const handleSave = () => { | ||
if (!canSubmit.value) { | ||
return | ||
} | ||
const grid = toRaw(inputValues) | ||
if (isEdit.value) { | ||
updateGrid(id.value, { | ||
...grid, | ||
}) | ||
} else { | ||
const newGrid: Grid<GridWidget> = { | ||
id: createGridId<GridWidget>(grid, tempGridLayout.value), | ||
title: grid.title, | ||
grid: [], | ||
} | ||
addGrid(newGrid) | ||
selectedLayoutId.value = newGrid.id | ||
} | ||
handleCancel() | ||
} | ||
watchEffect(() => { | ||
canSubmit.value = !!inputValues.title && !inputErrors.title | ||
}) | ||
onMounted(() => { | ||
setTimeout(() => { | ||
const input = document?.querySelector( | ||
'lukso-input' | ||
) as unknown as HTMLElement | ||
input?.shadowRoot?.querySelector('input')?.focus() | ||
}, INPUT_FOCUS_DELAY) | ||
Object.assign(inputValues, modal?.data?.grid || DEFAULT_PROPERTIES) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="p-6"> | ||
<div class="heading-inter-21-semi-bold pb-4"> | ||
{{ formatMessage(isEdit ? 'edit_grid_title' : 'add_grid_title') }} | ||
</div> | ||
<div class="paragraph-inter-14-regular pb-6"> | ||
{{ | ||
formatMessage(isEdit ? 'edit_grid_description' : 'add_grid_description') | ||
}} | ||
</div> | ||
|
||
<lukso-input | ||
.value="inputValues.title" | ||
:placeholder="formatMessage('add_grid_title_placeholder')" | ||
:error="inputErrors.title" | ||
is-full-width | ||
autofocus | ||
@on-input="handleTitleChange" | ||
></lukso-input> | ||
|
||
<!-- Buttons --> | ||
<div class="grid grid-cols-[max-content,auto] pt-6"> | ||
<lukso-button variant="text" @click="handleCancel"> | ||
{{ formatMessage('add_widget_cancel') }} | ||
</lukso-button> | ||
<lukso-button | ||
:disabled="!canSubmit ? true : undefined" | ||
variant="landing" | ||
is-full-width | ||
@click="handleSave" | ||
> | ||
{{ formatMessage('add_widget_confirm') }} | ||
</lukso-button> | ||
</div> | ||
</div> | ||
</template> |
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,40 @@ | ||
<script setup lang="ts"> | ||
const { closeModal, modal } = useModal() | ||
const { formatMessage } = useIntl() | ||
const { removeGrid } = useGrid() | ||
const handleDelete = async () => { | ||
removeGrid(modal?.data?.id) | ||
closeModal() | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="flex flex-col rounded-12 bg-neutral-98 p-6 text-center"> | ||
<div class="heading-inter-21-semi-bold pb-4"> | ||
{{ formatMessage('modal_delete_grid_title') }} | ||
</div> | ||
<div class="paragraph-inter-16-regular"> | ||
<lukso-sanitize | ||
:html-content=" | ||
formatMessage('modal_delete_grid_content', { | ||
title: `<strong>${modal?.data?.title}</strong>`, | ||
}) | ||
" | ||
></lukso-sanitize> | ||
</div> | ||
<div class="grid grid-cols-[max-content,auto]"> | ||
<lukso-button variant="text" @click="closeModal" class="mt-6"> | ||
{{ formatMessage('modal_delete_grid_cancel') }} | ||
</lukso-button> | ||
<lukso-button | ||
variant="danger" | ||
is-full-width | ||
@click="handleDelete" | ||
class="mt-6" | ||
> | ||
{{ formatMessage('modal_delete_grid_confirm') }} | ||
</lukso-button> | ||
</div> | ||
</div> | ||
</template> |
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,98 @@ | ||
<script setup lang="ts"> | ||
import type { SelectStringOption } from '@lukso/web-components' | ||
const { modal, closeModal } = useModal() | ||
const { formatMessage } = useIntl() | ||
const { tempGridLayout, selectedLayoutId } = storeToRefs(useGridStore()) | ||
const { addGridLayoutItem, removeGridLayoutItem, getGridById } = useGrid() | ||
const selectedOption = ref<string>() | ||
const canSubmit = computed( | ||
() => selectedOption.value !== selectedLayoutId.value | ||
) | ||
const options = computed<SelectStringOption[]>(() => { | ||
return tempGridLayout.value.map(grid => ({ | ||
id: grid.id, | ||
value: grid.title, | ||
})) | ||
}) | ||
const selectedOptionValue = computed(() => { | ||
const grid = tempGridLayout.value.find( | ||
grid => grid.id === selectedOption.value | ||
) | ||
return { | ||
id: grid?.id, | ||
value: grid?.title, | ||
} | ||
}) | ||
const handleChange = async (customEvent: CustomEvent) => { | ||
const option = customEvent.detail.value as SelectStringOption | ||
selectedOption.value = option.id | ||
} | ||
const handleCancel = () => { | ||
closeModal() | ||
} | ||
const handleSave = () => { | ||
if (!canSubmit.value) { | ||
return | ||
} | ||
const duplicatedWidget = createWidgetObject({ | ||
type: modal?.data?.type, | ||
properties: modal?.data?.properties, | ||
w: modal?.data?.w, | ||
h: modal?.data?.h, | ||
}) | ||
removeGridLayoutItem(modal?.data?.id) | ||
addGridLayoutItem( | ||
duplicatedWidget, | ||
getGridById(tempGridLayout.value, selectedOption.value) | ||
) | ||
handleCancel() | ||
} | ||
onMounted(() => { | ||
selectedOption.value = selectedLayoutId.value | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="p-6"> | ||
<div class="heading-inter-21-semi-bold pb-4"> | ||
{{ formatMessage('move_widget_title') }} | ||
</div> | ||
<div class="paragraph-inter-14-regular pb-6"> | ||
{{ formatMessage('move_widget_description') }} | ||
</div> | ||
|
||
<lukso-select | ||
:value="JSON.stringify(selectedOptionValue)" | ||
:options="JSON.stringify(options)" | ||
is-full-width | ||
autofocus | ||
@on-select="handleChange" | ||
></lukso-select> | ||
|
||
<!-- Buttons --> | ||
<div class="grid grid-cols-[max-content,auto] pt-6"> | ||
<lukso-button variant="text" @click="handleCancel"> | ||
{{ formatMessage('add_widget_cancel') }} | ||
</lukso-button> | ||
<lukso-button | ||
:disabled="!canSubmit ? true : undefined" | ||
variant="landing" | ||
is-full-width | ||
@click="handleSave" | ||
> | ||
{{ formatMessage('add_widget_confirm') }} | ||
</lukso-button> | ||
</div> | ||
</div> | ||
</template> |
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
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
Oops, something went wrong.