Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
feat: improved input-group
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianKienle committed Jun 21, 2019
1 parent 33f6869 commit 93f872f
Show file tree
Hide file tree
Showing 28 changed files with 413 additions and 115 deletions.
8 changes: 4 additions & 4 deletions src/components/Combobox/Combobox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</template>

<template #after="{ toggleCompletions }">
<FdButton
<FdInputGroupButton
@click="toggleCompletions"
:compact="compact"
icon="navigation-down-arrow"
Expand All @@ -43,10 +43,10 @@
<script>
import { Uid } from "./../../mixins";
import FdInput from "./../Form/Controls/Input.vue";
import FdButton from "./../Button/Button.vue";
import FdComboboxBase from "./../ComboboxBase/ComboboxBase.vue";
import FdMenu from "./../Menu/Menu.vue";
import FdMenuList from "./../Menu/MenuList.vue";
import FdInputGroupButton from "./../InputGroup/InputGroupButton.vue";
export default {
name: "FdCombobox",
Expand All @@ -63,9 +63,9 @@ export default {
components: {
FdMenu,
FdMenuList,
FdButton,
FdComboboxBase,
FdInput
FdInput,
FdInputGroupButton
},
props: {
value: { type: String, default: null },
Expand Down
29 changes: 18 additions & 11 deletions src/components/ComboboxBase/ComboboxBase.vue
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
<template>
<FdPopover ref="popover" adjustsBodyWidth placement="bottom-start">
<fd-popover ref="popover" adjustsBodyWidth placement="bottom-start">
<template #control="{ hide, show, toggle }">
<div class="fd-combobox-control">
<FdInputGroup
:compact="compact"
afterClass="fd-input-group__addon--button"
>
<slot name="input" :hideCompletions="hide" :showCompletions="show" />
<fd-input-group :compact="compact">
<template #input>
<slot
name="input"
:hideCompletions="hide"
:showCompletions="show"
/>
</template>

<template #after>
<slot name="after" :toggleCompletions="toggle" />
<fd-input-group-addon>
<slot name="after" :toggleCompletions="toggle" />
</fd-input-group-addon>
</template>
</FdInputGroup>
</fd-input-group>
</div>
</template>

<template #default="{hide}">
<slot :hideCompletions="hide" />
</template>
</FdPopover>
</fd-popover>
</template>

<script>
import { Uid } from "./../../mixins";
import { InputGroup as FdInputGroup } from "./../Form";
import FdInputGroup from "./../InputGroup/InputGroup.vue";
import FdInputGroupAddon from "./../InputGroup/InputGroupAddon.vue";
import FdPopover from "./../Popover/Popover.vue";
export default {
Expand All @@ -35,7 +41,8 @@ export default {
},
components: {
FdPopover,
FdInputGroup
FdInputGroup,
FdInputGroupAddon
},
computed: {
popover() {
Expand Down
1 change: 0 additions & 1 deletion src/components/Form/Controls/Checkbox.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<input
type="checkbox"
class="fd-form__control"
:id="inputId"
:class="inputClasses"
:disabled="disabled ? '' : null"
Expand Down
11 changes: 9 additions & 2 deletions src/components/Form/Controls/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
/>
<input
v-else
class="fd-input fd-form__control"
:class="inputClasses"
:class="inputClasses_"
:id="inputId"
:readonly="readonly ? '' : null"
:disabled="disabled ? '' : null"
Expand Down Expand Up @@ -56,6 +55,14 @@ export default {
focused: false
};
},
computed: {
inputClasses_() {
return {
...this.inputClasses,
"fd-input": !this.plain
};
}
},
props: {
placeholder: $default(""),
type: $default("text"),
Expand Down
9 changes: 7 additions & 2 deletions src/components/Form/Controls/InputMixin.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { $enum, $default } from "./Helper/prop";
import { Compactable } from "./../../../mixins";

// The InputMixin can be used by input controls in order to gain a useful default set
// of props, injections and computed properties.
export default {
inject: {
itemId: { default: null }
},
mixins: [Compactable],
props: {
state: $enum("valid", "invalid", "warning"),
required: $default(false),
compact: $default(false),
disabled: $default(false),
readonly: $default(false)
readonly: $default(false),
// If true, certain classes like fd-input and fd-form__control
// are not added to the input-element.
plain: $default(false)
},
computed: {
inputStateClasses() {
Expand All @@ -20,6 +24,7 @@ export default {
},
inputClasses() {
return {
"fd-form__control": !this.plain,
"fd-input--compact": this.compact,
...this.inputStateClasses,
"is-required": this.required
Expand Down
1 change: 0 additions & 1 deletion src/components/Form/Controls/Radio.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<input
type="radio"
class="fd-form__control"
:class="inputClasses"
:id="inputId"
:disabled="disabled ? '' : null"
Expand Down
1 change: 0 additions & 1 deletion src/components/Form/Controls/Select.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<template>
<select
class="fd-form__control"
:class="inputClasses"
:id="inputId"
:readonly="readonly ? '' : null"
Expand Down
1 change: 0 additions & 1 deletion src/components/Form/Controls/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { default as Input } from "./Input.vue";
export { default as InputGroup } from "./InputGroup.vue";
export { default as Select } from "./Select.vue";
export { default as TextArea } from "./TextArea.vue";
export { default as Toggle } from "./Toggle.vue";
Expand Down
3 changes: 0 additions & 3 deletions src/components/Form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Legend from "./Legend.vue";
import FieldSet from "./FieldSet.vue";
import Form from "./Form.vue";
import Input from "./Controls/Input.vue";
import InputGroup from "./Controls/InputGroup.vue";
import Select from "./Controls/Select.vue";
import TextArea from "./Controls/TextArea.vue";
import Toggle from "./Controls/Toggle.vue";
Expand All @@ -19,7 +18,6 @@ import { pluginify } from "./../../util";
export default pluginify(
Form,
Input,
InputGroup,
Select,
TextArea,
Toggle,
Expand All @@ -36,7 +34,6 @@ export default pluginify(
export {
Form,
Input,
InputGroup,
Select,
TextArea,
Toggle,
Expand Down
19 changes: 19 additions & 0 deletions src/components/FormLabel/FormLabel.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template>
<label class="fd-form__label" :aria-required="String(required)">
<slot /><template v-if="required"
><slot name="required">*</slot></template
>
</label>
</template>

<script>
export default {
name: "FdFormLabel",
props: {
required: {
type: Boolean,
default: false
}
}
};
</script>
4 changes: 4 additions & 0 deletions src/components/FormLabel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import FormLabel from "./FormLabel.vue";
import { pluginify } from "./../../util";
export default pluginify(FormLabel);
export { FormLabel };
2 changes: 1 addition & 1 deletion src/components/Icon/Icon.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<span :class="classes" />
<span :class="classes" role="presentation" />
</template>

<script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
<template>
<div class="fd-input-group" :class="classes">
<span
v-if="hasBefore"
class="fd-input-group__addon fd-input-group__addon--before"
>
<slot name="before">{{ before }}</slot>
</span>
<slot />
<span v-if="hasAfter" :class="afterClasses">
<fd-addon-before-provider>
<slot name="before">
{{ before }}
</slot>
</fd-addon-before-provider>
<slot name="before-input" />
<slot name="input" />
<slot name="after-input" />
<fd-addon-after-provider>
<slot name="after">{{ after }}</slot>
</span>
</fd-addon-after-provider>
</div>
</template>

<script>
import { CompactableContainer } from "./../../mixins";
const CreateAddon = context => ({
provide() {
return {
$_fdInputGroupAddonContext: context
};
},
render() {
return this.$scopedSlots.default();
}
});
const FdAddonBeforeProvider = CreateAddon("before");
const FdAddonAfterProvider = CreateAddon("after");
export default {
name: "FdInputGroup",
mixins: [CompactableContainer],
components: { FdAddonBeforeProvider, FdAddonAfterProvider },
props: {
before: { type: String, default: null },
after: { type: String, default: null },
Expand Down
34 changes: 34 additions & 0 deletions src/components/InputGroup/InputGroupAddon.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<template>
<span class="fd-input-group__addon" :class="classes"><slot /></span>
</template>

<script>
export default {
name: "FdInputGroupAddon",
inject: {
$_fdInputGroupAddonContext: { default: null }
},
provide() {
return {
$_fdInputGroupAddon: this
};
},
data() {
return {
hasButton: false
};
},
computed: {
addonContext() {
return this.$_fdInputGroupAddonContext;
},
classes() {
return {
"fd-input-group__addon--button": this.hasButton,
"fd-input-group__addon--before": this.addonContext === "before",
"fd-input-group__addon--after": this.addonContext === "after"
};
}
}
};
</script>
18 changes: 18 additions & 0 deletions src/components/InputGroup/InputGroupButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<fd-button styling="light" v-bind="$attrs" v-on="$listeners"
><slot
/></fd-button>
</template>

<script>
import FdButton from "./../Button/Button.vue";
export default {
name: "FdInputGroupButton",
components: { FdButton },
inject: ["$_fdInputGroupAddon"],
mounted() {
this.$_fdInputGroupAddon.hasButton = true;
}
};
</script>
23 changes: 23 additions & 0 deletions src/components/InputGroup/InputGroupClearButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template>
<!-- the inline style is a workaround and should be removed -->
<!-- once it has been fixed in fund. styles. -->
<button
class="fd-input-group__button fd-input-group__button--clear"
style="z-index: 2;"
aria-label="Clear"
v-bind="$attrs"
v-on="$listeners"
>
<slot />
</button>
</template>

<script>
export default {
name: "FdInputGroupClearButton",
inject: ["$_fdInputGroupAddon"],
mounted() {
this.$_fdInputGroupAddon.hasButton = true;
}
};
</script>
22 changes: 22 additions & 0 deletions src/components/InputGroup/InputGroupSearch.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template>
<fd-input-group>
<template #input>
<fd-input type="search" plain placeholder="Enter Search Term…" />
</template>
<template #after-input>
<fd-input-group-addon>
<slot name="clear" />
</fd-input-group-addon>
</template>
</fd-input-group>
</template>

<script>
import FdInputGroup from "./InputGroup.vue";
import FdInputGroupAddon from "./InputGroupAddon.vue";
export default {
name: "FdInputGroupSearch",
components: { FdInputGroup, FdInputGroupAddon }
};
</script>
Loading

0 comments on commit 93f872f

Please sign in to comment.