-
Notifications
You must be signed in to change notification settings - Fork 25
feat: add floating action button #1688
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
7 commits
Select commit
Hold shift + click to select a range
fce1b18
feat: add floation action button
AlexAndBear 970a307
add to docs
AlexAndBear e21c085
Integrate
AlexAndBear ecd2d8e
fix types
AlexAndBear c339386
fix types
AlexAndBear 2dc5634
adjust interface
AlexAndBear 33cda58
OcFloatingActionButton.vue aktualisieren
AlexAndBear 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
53 changes: 53 additions & 0 deletions
53
.../design-system/docs/components/OcFloatingActionButton/OcFloatingActionButton.md
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,53 @@ | ||
| --- | ||
| title: OcFloatingActionButton component | ||
| next: false | ||
| prev: false | ||
| --- | ||
|
|
||
| # OcFloatingActionButton component | ||
|
|
||
| ## Description | ||
|
|
||
| The `OcFloatingActionButton` component displays a button that floats above an interface and represents the primary or | ||
| most common action of a screen. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Default | ||
|
|
||
| The default use case displays a menu of stacked buttons. | ||
|
|
||
| ::: livecode | ||
|
|
||
| ```html | ||
| <oc-floating-action-button | ||
| aria-label="Floating action button" | ||
| class="!static" | ||
| :items="[ | ||
| { label: 'File', icon: 'file', to: { path: '/' } }, | ||
| { label: 'Folder', icon: 'folder', to: { path: '/' } }, | ||
| { label: 'Public link', icon: 'link', to : { path: '/' } } | ||
| ]" | ||
| /> | ||
| ``` | ||
|
|
||
| ::: | ||
|
|
||
| ### Action mode | ||
|
|
||
| While setting `mode` to `action`, only the primary Floating Action Button will be displayed. | ||
|
|
||
| ::: livecode | ||
|
|
||
| ```html | ||
| <oc-floating-action-button | ||
| aria-label="Floating action button" | ||
| mode="action" | ||
| class="!static" | ||
| :to="{ path: '/' }" | ||
| /> | ||
| ``` | ||
|
|
||
| ::: | ||
|
|
||
| ::: component-api |
95 changes: 95 additions & 0 deletions
95
packages/design-system/src/components/OcFloatingActionButton/OcFloatingActionButton.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,95 @@ | ||
| <template> | ||
| <div class="fixed flex flex-col items-end bottom-[20px] right-[20px]"> | ||
| <template v-if="expanded"> | ||
| <oc-button | ||
| v-for="item in items" | ||
| :key="item.label" | ||
| class="mb-2 rounded-full" | ||
| appearance="filled" | ||
| color-role="primary" | ||
| :type="item.to ? 'router-link' : 'button'" | ||
| :to="item.to" | ||
| @click="onChildButtonClicked(item)" | ||
| > | ||
| <oc-icon :name="item.icon" /> | ||
| <span v-text="item.label" /> | ||
AlexAndBear marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </oc-button> | ||
| </template> | ||
| <oc-button | ||
| class="rounded-full size-14" | ||
| appearance="filled" | ||
| color-role="primary" | ||
| :aria-label="computedAriaLabel" | ||
| :type="mode === 'action' && to ? 'router-link' : 'button'" | ||
| :to="to" | ||
| @click="onPrimaryButtonClicked" | ||
| > | ||
| <oc-icon :name="expanded ? 'close' : 'add'" fill-type="line" /> | ||
| </oc-button> | ||
| </div> | ||
| </template> | ||
| <script setup lang="ts"> | ||
| import { computed, ref, unref } from 'vue' | ||
| import { RouteLocationRaw } from 'vue-router' | ||
| import { useGettext } from 'vue3-gettext' | ||
|
|
||
| export interface Props { | ||
| /** | ||
| * @docs The aria label of the primary action button. | ||
AlexAndBear marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * @default 'Open actions menu' | ||
| */ | ||
| ariaLabel?: string | ||
| /** | ||
| * @docs The mode of the floating action button. | ||
| * @default menu | ||
| */ | ||
| mode?: 'action' | 'menu' | ||
| /** | ||
| * @docs The route location of the primary action button when the `mode` is set to `action`. | ||
| */ | ||
| to?: RouteLocationRaw | ||
| /** | ||
| * @docs The handler of the primary action button when the `mode` is set to `action`. | ||
| */ | ||
| handler?: () => void | ||
| /** | ||
| * @docs The menu items of the floating action button element. | ||
| */ | ||
| items?: { | ||
| icon: string | ||
| label: string | ||
| handler?: () => void | ||
| to?: RouteLocationRaw | ||
| }[] | ||
| } | ||
|
|
||
| const { | ||
| mode = 'menu', | ||
| ariaLabel = '', | ||
| items = [], | ||
| handler = null, | ||
| to = null | ||
| } = defineProps<Props>() | ||
|
|
||
| const { $gettext } = useGettext() | ||
|
|
||
| const expanded = ref(false) | ||
|
|
||
| const computedAriaLabel = computed(() => { | ||
| return ariaLabel ? ariaLabel : $gettext('Open actions menu') | ||
| }) | ||
|
|
||
| const onPrimaryButtonClicked = () => { | ||
| if (mode === 'action') { | ||
| handler?.() | ||
| return | ||
| } | ||
|
|
||
| expanded.value = !unref(expanded) | ||
| } | ||
|
|
||
| const onChildButtonClicked = (item: Props['items'][number]) => { | ||
| item.handler?.() | ||
| expanded.value = false | ||
| } | ||
| </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
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
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.