Skip to content
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

feat(ui): add icon to WdsTextInput. WF-36 #511

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/ui/src/core_components/content/CoreDataframe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<div v-if="fields.enableSearch.value === 'yes'">
<WdsTextInput
class="search"
placeholder="Search..."
placeholder="Search"
left-icon="search"
@change="handleSearchChange"
/>
</div>
Expand Down Expand Up @@ -316,7 +317,7 @@ const slicedTable = computed(() => {

const gridStyle = computed(() => {
const fontStyle = fields.fontStyle.value;
let templateColumns: string, maxHeight: number;
let templateColumns: string;

if (columnWidths.value.length == 0) {
templateColumns = `repeat(${columnCount.value}, minmax(min-content, 1fr))`;
Expand All @@ -342,7 +343,7 @@ const endpointStyle = computed(() => {
};
});

function handleScroll(ev: Event) {
function handleScroll() {
const scrollTop = gridContainerEl.value.scrollTop;
relativePosition.value =
scrollTop /
Expand Down Expand Up @@ -395,7 +396,7 @@ function handleSetOrder(ev: MouseEvent, columnName: string) {
};
}

function getIndexFromArrowTable(table: Table<any>) {
function getIndexFromArrowTable(table: Table) {
const pandasMetadataJSON = table.schema.metadata.get("pandas");
if (!pandasMetadataJSON) return [];
const pandasMetadata = JSON.parse(pandasMetadataJSON);
Expand Down Expand Up @@ -442,7 +443,7 @@ async function applyOrder() {
return;
}

let orderCriterion: any;
let orderCriterion: string | object;

if (orderSetting.value.descending) {
orderCriterion = aq.desc(orderSetting.value.columnName);
Expand Down
50 changes: 46 additions & 4 deletions src/ui/src/wds/WdsTextInput.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
<template>
<input v-model="model" type="text" />
<div
v-if="leftIcon"
class="WdsTextInput WdsTextInput--leftIcon"
@click="input.focus()"
>
<i class="material-symbols-outlined">{{ leftIcon }}</i>
<input
ref="input"
v-model="model"
type="text"
:placeholder="placeholder"
/>
</div>
<input v-else v-model="model" type="text" class="WdsTextInput" />
</template>

<script setup lang="ts">
const model = defineModel<string>();
import { ref } from "vue";

const model = defineModel({ type: String });

defineProps({
leftIcon: { type: String, required: false, default: undefined },
placeholder: { type: String, required: false, default: undefined },
});

const input = ref();
</script>

<style scoped>
input {
.WdsTextInput {
width: 100%;
margin: 0;
border: 1px solid var(--separatorColor);
Expand All @@ -19,8 +41,28 @@ input {
background: transparent;
}

input:focus {
.WdsTextInput:focus,
.WdsTextInput--leftIcon:focus-within {
border: 1px solid var(--softenedAccentColor);
box-shadow: 0px 0px 0px 3px rgba(81, 31, 255, 0.05);
}

.WdsTextInput--leftIcon {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey I guess nothing wrong with it but just wanted to know, why do you do

.WdsTextInput--leftIcon

instead of

.WdsTextInput.leftIcon

It'd more compact since

class="WdsTextInput WdsTextInput--leftIcon"

becomes

class="WdsTextInput leftIcon"

Since the styles are scoped there's no risk of another leftIcon bothering you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a habit of following BEM convention. It helps to improve the organization of the CSS. So the *--leftIcon acts as a "modifier". A modifier means to change appearance, behavior or state of an element.

But I agree that here, it's not necessary since the style is scoped

cursor: pointer;
display: flex;
gap: 8px;
}

.WdsTextInput--leftIcon i {
color: #4f4f4f;
}

.WdsTextInput--leftIcon input {
border: none;
}
.WdsTextInput--leftIcon input:focus {
border: none;
box-shadow: none;
outline: none;
}
</style>
Loading