From 61e6b3fa0f101b12addfe9776ad2ac332b3f6545 Mon Sep 17 00:00:00 2001 From: upsiflu Date: Sun, 2 Feb 2025 20:16:16 +0100 Subject: [PATCH] refactor(ui): improve textarea component --- front/src/components/ui/Textarea.vue | 83 +++++++---- front/src/components/ui/textarea.scss | 75 ++++------ front/ui-docs/components/ui/textarea.md | 179 ++++++++++++++++-------- 3 files changed, 208 insertions(+), 129 deletions(-) diff --git a/front/src/components/ui/Textarea.vue b/front/src/components/ui/Textarea.vue index 3f10a1bcb..22bbec18f 100644 --- a/front/src/components/ui/Textarea.vue +++ b/front/src/components/ui/Textarea.vue @@ -1,14 +1,22 @@ diff --git a/front/src/components/ui/textarea.scss b/front/src/components/ui/textarea.scss index b6670db5a..348e2a6be 100644 --- a/front/src/components/ui/textarea.scss +++ b/front/src/components/ui/textarea.scss @@ -1,10 +1,9 @@ .funkwhale { &.textarea-label { - display: block; > .label { - padding-bottom: 4px; - font-size:14px; - font-weight:600; + margin-top: -18px; + font-size: 14px; + font-weight: 600; } } &.textarea { @@ -15,19 +14,27 @@ background-color: var(--fw-bg-color); } + > textarea { + resize: none; + order: 0; + outline: none; + border: none; + } + + overflow: hidden; + > .textarea-buttons { - border-top: 1px solid var(--fw-buttons-border-color); + flex-wrap: wrap; + // Offset padding of the textarea + margin: -8px; - > .funkwhale.button:not(:hover):not(:active):not(.is-active) { - --fw-bg-color: transparent; + > button+button { + border-top-left-radius: 0; + border-bottom-left-radius: 0; } - - > .separator { - background-color: var(--fw-buttons-border-color); - } - - > .letter-count { - color: var(--fw-buttons-border-color); + > button:has(+button) { + border-top-right-radius: 0; + border-bottom-right-radius: 0; } } @@ -42,8 +49,8 @@ } &.has-preview, - &:focus-within { - --fw-border-color: var(--fw-primary) !important; + &:hover:focus-within { + --fw-border-color: transparent; --fw-bg-color: var(--fw-blue-010); } } @@ -59,16 +66,17 @@ } &.has-preview, - &:focus-within { - --fw-border-color: var(--fw-primary) !important; + &:hover:focus-within { + --fw-border-color: transparent; --fw-bg-color: var(--fw-gray-800); } } position: relative; padding: 8px; - border-radius: var(--fw-border-radius); + // Make border trace the radius of the buttons smoothly + border-radius: calc(var(--fw-border-radius) + 4px); &.has-preview, &:focus-within { @@ -100,10 +108,10 @@ } > textarea { + line-height: 1.5rem; display: block; width: 100%; - min-height: 160px; - padding: 8px 12px 40px; + padding: 8px 12px 8px; font-family: monospace; background: transparent; @@ -116,33 +124,12 @@ display: flex; align-items: center; - position: absolute; - bottom: 8px; - left: 8px; - right: 8px; + position: relative; opacity: 0; - transform: translateY(.5rem); + transform: translateY(1rem) scale(1.03); pointer-events: none; transition: all .2s ease; - - padding-top: 4px; - - > .funkwhale.button { - font-size: 1.2rem; - padding: 0.2em; - } - - > .separator { - width: 1px; - height: 28px; - margin: 0 8px; - } - - > .letter-count { - margin-left: auto; - padding-right: 16px; - } } } } diff --git a/front/ui-docs/components/ui/textarea.md b/front/ui-docs/components/ui/textarea.md index ccc424653..495dca74c 100644 --- a/front/ui-docs/components/ui/textarea.md +++ b/front/ui-docs/components/ui/textarea.md @@ -1,86 +1,71 @@ ```ts -import Textarea from "~/components/ui/Textarea.vue" +import Textarea from "~/components/ui/Textarea.vue"; ``` # Textarea -Textareas are input blocks that enable users to write in textual information. These blocks are used throughout the Funkwhale interface for entering item descriptions, moderation notes, and custom notifications. +Textareas are input blocks that enable users to write formatted text (format: Markdown). These blocks are used throughout the Funkwhale interface for entering item descriptions, moderation notes, and custom notifications. + +::: details Props + +```ts +const { + charLimit = 5000, + placeholder = "", + minLines = 3, + ...props +} = defineProps<{ + label?: string; + placeholder?: string; + charLimit?: number; + minLines?: number | string; + autofocus?: true; + required?: true; +}>(); +``` -::: tip -Funkwhale supports Markdown syntax in textarea blocks. ::: -| Prop | Data type | Required? | Description | -| --------------- | --------- | --------- | ------------------------------------------------------------------ | -| `max` | Number | No | The maximum number of characters a user can enter in the textarea. | -| `placeholder` | String | No | The placeholder text shown on an empty textarea. | -| `v-model:value` | String | Yes | The text entered into the textarea. | +Create a textarea and attach its input to a value using a `v-model` of type `string` (required): -## Textarea model - -Create a textarea and attach its input to a value using a `v-model` directive. +```ts +const text = ref("# Funk\nwhale"); +``` ```vue-html{2} - ``` - +``` + +