0.1.98 • Published 4 years ago

@bluexlab/bluex-components v0.1.98

Weekly downloads
2
License
UNLICENSED
Repository
gitlab
Last release
4 years ago

bluex-components

Installation

npm install @bluexlab/bluex-components

Mocking in unit tests

You can expand on this, but the most basic working mock works as follows:

jest.mock('@bluexlab/bluex-components', () => ({
  MaskedInput: { name: 'MaskedInput' },
  Dropdown: { name: 'Dropdown' }
}))

Components

Examples from React Native (so you can see the similarities): TextInput Switch AlertIOS

A note on input masks

If you're not using an input mask, any component that accepts input will default to ascii only input. These components are designed for BluexTrade engineering. Ascii only was a company decision. You can get around this by passing an empty object to the :mask prop.

Checkbox

Custom checkbox component to meet design specs

Props:

Proptype(s)Description
checkboxIdstring, number(required) Used for input ID and label for value.
labelstring, number(required) Used for the label string to the right of the text box.
selectedboolean(required) Whether the checkbox is checked or not.
onTogglefunction(required) Is called when checked/unchecked. Parent should update the selected prop.

Example:

<Checkbox
  :checkbox-id="'someCheckbox'"
  :label="$t('some_locale_string')"
  :selected="someCheckboxSelected"
  :on-select="handleClickCheckbox"
/>

DatePicker

Wraps vue2-datepicker plugin in a custom component

Props:

Proptype(s)Description
datestring, date, number(optional) Even though this is marked as optional, it needs to be received by the component. A null value is allowed, which does not work with prop type checking. So date defaults to "null".
startDatedate(optional) Allows setting a start date. Use moment().toDate()
requiredboolean(optional) Will show an asterisk and be used when checking if a selection has been made.
onChangefunctionCalled when date is changed. Parent should update date prop.
promptRequiredboolean(optional) If required is true, and promptRequired is true, dropdown will show a red border and message below it. When a selection is made, the border and message are hidden
titlestring(optional) Title display above the date picker input.
errorMessagestringMessage to show when required and promptRequired are true. Defaults to "This is a required field. Please complete this field to continue" as received from en.json.

Example:

<DatePicker
  :date="dateForPicker"
  :on-change="handleDateChange"
/>

Dropdown

Acts like a React controlled component. Uses vue-inputmask. Can be used as a traditional listbox with no input (but will jump to a match if you start typing while it's focused), works with keyboard navgation (arrow up, down, enter, tab), and can also act as a searchbar similar to those seen on search engines.

Props:

Proptype(s)Description
valuestring, number(required) String or number for the currently selected or active item.
onSelectfunction(required) Called on select. Parent should then update value prop with data from selection.
onInputfunction(required) Called on input. Parent should then update value prop with data from selection.
onBlurfunction(optional) Called on blur.
onFocusfunction(optional) Called on focus.
dataarray of objects(required) A data array of objects with keys: id: Used when returning data value: String or number for currently selected item valueForBackend: The value used for your GraphQL mutation. nested: An optional array to include nested objects with the same structure. This only goes one level deep.
maskobject(optional) Used for masked input. Use or add to directives/inputMasks.js. If no mask is provided, it will default to ASCII only for searchable (accepts input) and no mask for non-searchable (for example, this will allow Chinese text to render for the chosen item)
typestringinput type (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#%3Cinput%3E_types)
titlestring(optional) Title display above the dropdown.
placeholderstring(optional) Placeholder text.
requiredboolean(optional) Will show an asterisk and be used when checking if a selection has been made.
promptRequiredboolean(optional) If required is true, and promptRequired is true, dropdown will show a red border and message below it. When a selection is made, the border and message are hidden.
showArrowbooleanShow or hide the arrow indicating it's a dropdown. Defaults to true.
maxToShownumberMaximum dropdown items to show when open before scrolling
searchablebooleanIf not set, you'll get the default behavior of a dropdown. Click to show items, select an item and it closes. If searchable="true", it acts as an input with results displaying in the dropdown list.
errorMessagestringMessage to show when required and promptRequired are true. Defaults to "This is a required field. Please complete this field to continue" as received from en.json.
disableDropdownbooleandisables dropdown by using pointer-events: none and adds opacity
labelInsidebooleanUses style seen in Quotes Search pages (the label is inside the input instead of above it)

Example:

<Dropdown
  :data="arrayForDropdown"
  :title="$t('your_locale_string')"
  :on-select="handleDropdownSelection"
  :searchable="false"
  :value="dropdownValue"
/>

InputWithDropdown

Dropdown and MaskedInput combined

Proptype(s)Description
inputValuestring, number(required) String or number for the currently typed input.
dropdownValuestring, number(required) String or number for the currently selected or active item.
onSelectfunction(required) Called on select. Parent should then update value prop with data from selection.
onInputfunction(required) Called on input. Parent should then update value prop with data from selection.
dropdownDataarray of objects(required) A data array of objects with keys: id: Used when returning data value: String or number for currently selected item valueForBackend: The value used for your GraphQL mutation.
maskobject(optional) Used for masked input. Use or add to directives/inputMasks.js.
typestringinput type (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#%3Cinput%3E_types)
titlestring(optional) Title display above the dropdown.
placeholderstring(optional) Placeholder text.
requiredboolean(optional) Will show an asterisk and be used when checking if a selection has been made.
promptRequiredboolean(optional) If required is true, and promptRequired is true, dropdown will show a red border and message below it. When a selection is made, the border and message are hidden.
maxToShownumber(optional) Maximum dropdown items to show when open before scrolling
errorMessagestring(optional) Message to show when required and promptRequired are true. Defaults to "This is a required field. Please complete this field to continue" as received from en.json.
vobject(optional) object for vuelidate plugin
autocompletestring(optional) allows custom autocomplete setting (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete)
disableInputbooleandisables text input by using pointer-events: none and adds opacity
disableDropdownbooleandisables dropdown by using pointer-events: none and adds opacity

Example:

<InputWithDropdown
  :title="$t('locale_string')"
  :on-input="handleInput"
  :input-value="inputValue"
  :dropdown-value="dropdownValue"
  :on-select="handleSelect"
  :dropdown-data="arrayForDropdown"
/>

MaskedInput

Acts like a React controlled component. Uses vue-inputmask. On blur, leading and trailing whitespace is trimmed and returned to the parent via onInput.

Props:

Proptype(s)Description
valuestring, number(required) String or number for the currently selected or active item.
onInputfunction(required) Called on input and returns inputed string value. Parent should then update value prop with data from selection.
onBlurfunction(optional) Called on blur. Returns entire element object.
onFocusfunction(optional) Called on focus. Returns entire element object.
maskobject(optional) Used for masked input. Use or add to directives/inputMasks.js. Defaults to ASCII, pass an
empty object to allow all text
typestring(optional) HTML input type
titlestring(optional) Title display above the input.
disabledbooleanIf true, input will be disabled and style will reflect that it cannot be edited.
placeholderstring(optional) Placeholder text.
requiredboolean(optional) Will show an asterisk and be used when checking if a selection has been made.
promptRequiredboolean(optional) If required is true, and promptRequired is true, dropdown will show a red border and message below it. When a selection is made, the border and message are hidden.
errorMessagestringMessage to show when required and promptRequired are true. Defaults to "This is a required field. Please complete this field to continue" as received from en.json.

Example:

<MaskedInput
  :title="$t('locale_string')"
  :on-input="handleInput"
  :required="true"
  :prompt-required="promptRequiredBool"
  :value="inputValue"
/>

Modal (can also be an error alert)

A modal component is in App.vue. You can render it via Vuex action (structure based on React Native's Alert component) which has been attached globally. You'll have to create this action in your code base and simply render Modal conditionally. Here's an example:

<Modal
  v-if="showModal"
  :settings="modalSettings"
  :close="closeModal"
/>

...

<script>
export {
  ...
  data () {
    ...
    showModal: false,
    modalSettings: {}
  },
  mounted () {
    this.vuexUnsubscribe = this.$store.subscribe(({ payload, type }) => {
      switch (type) {
        case 'setShowModal':
          this.showModal = true
          this.modalSettings = payload
          break
        ...
      }
    })
  }
}
</script>
// Show
  this.$toggleModal({
    modalType: 'confirmDelete', // If not included Modal will default to a generic modal
    title: $t('confirm_logout'),
    message: $t('cannot_be_undone'),
    buttons: [
      {
        title: $t('cancel'), // Required
        className: 'gray' // Styles button. className must match an existing button class as seen in app.scss
      },
      {
        title: $t('delete'),
        onClick: () => this.commitDelete(uuid), // If not included, Modal will close on click
        className: 'warning'
      }
    ],
    cancelable: false, // Optional. If true or not defined, clicking outside of the modal will close it. If false, close(x) button will be hidden.
  })
// Hide
this.$toggleModal({})

Available modalTypes and resulting bahavior: confirmAction: Shows warning symbol (exclamation point in a triangle). confirmDelete: Shows trashcan icon and default confirmation button color is red. confirmSuccess: Shows a checkmark in a circle. confirmInfo: Shows the letter "i" in a circle.

If modalType is received, Modal will render a plain modal with no image in the center and all buttons will be gray unless className is added to a button object

PaginationBar

As seen in bookings and documents list. Has previous and next bottons, and individual buttons for each page.

Props:

Proptype(s)Description
pageSizenumber(required) Number of pages per group. Correlates with your GraphQL API pageSize
numberOfResultsnumber(required) Total number of available results
currentPagenumber(required) Current page in view
onClickNextfunction(required) Callback function so you can get the next page if it exists
onClickPrevfunction(required) Callback function so you can go back a page (will not be called if on the first page
jumpToPagefunction(required) Callback function so you can get the current page from the API or local state
pageRangenumber(optional) Used to determine how many pages to show in the bar before displaying ellipsis

Example:

<PaginationBar
  :page-size="pageSize"
  :number-of-results="totalResults"
  :current-page="currentPage"
  :on-click-next="handleNext"
  :on-click-prev="handlePrevious"
  :jump-to-page="jumpToPage"
/>

PlaintextDropdown

A dropdown/listbox that does not accept typed input/searching. The seleted item is displayed as plain text, not inside of a container, and the list appears beneath it when clicked.

Proptype(s)Description
selectedstring, number(required) String or number for the currently selected or active item.
itemsarray(required) Items to display in the dropdown list
onSelectfunction(required) Called on select. Parent should then update value prop with data from selection.

Example:

<PlaintextDropdown
  :selected="selected"
  :items="arrayForDropdown"
  :on-select="handleSelect"
/>

RadioButton

Custom radio button

Proptype(s)Description
radioIdstring, number(required) Used to assign the label to the input
checkedboolean(required) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefchecked
onChangefunction(required) Returns radio ID prop to parent to determine that it's the currently selected radio button (because radio buttons should be selected one at a time)
labelstring(optional) Label text displayed next to the radio control

Example:

<RadioButton
  :label="'radio-button-1'"
  :radio-id="'radioButton1'"
  :checked="selected === 'radioButton1'"
  :on-change="handleSelect"
/>

Searchbar

Custom styled searchbar

Proptype(s)Description
onInputfunction(required) Called on input. Parent should then update value prop with entered string
valuestring, number(required) String or number for the currently inputted text
placeholderstring(optional) Shows placeholder in text input
promptRequiredboolean(optional) When true, it will add a class which outlines the input in red. Set to false to remove
onClearfunction(required) Called when input is cleared via clicking the "X" image
onEnterfunction(required) Called when hitting the enter key

Example:

<Searchbar
  :value="searchbarValue"
  :placeholder="$t('locale_string')"
  :on-input="handleSearchBarInput"
  :on-enter="handleSearchBarSubmit"
  :on-clear="handleSearchBarClear"
/>

Toggle

Like React Natives "Switch" component, toggles on or off on click.

Proptype(s)Description
valueboolean(required) Allows toggle to be on (true) or off (false)
onValueChangefunction(required) Called on click. Returns boolean.

Example:

<Toggle
  :on-value-change="handleToggle"
  :value="toggleValue"
/>

Tooltip

Accepts a slot for

Proptype(s)Description
loadingboolean(optional) shows/hides loader gif

Example:

<Tooltip :loading="someTogglingBoolean">
  <div>your stuff</div>
</Tooltip>

For absolute positioning, use a wrapper

<div class="your-item">
  <div class="your-item-tooltip-wrapper">
    <Tooltip :loading="someTogglingBoolean">
      <div>your stuff</div>
    </Tooltip>
  </div>
</div>
.your-item {
  position: relative;
  &-tooltip-wrapper {
    position: absolute;
    top: 0;
    left: 0;
  }
}
0.1.98

4 years ago

0.1.97

4 years ago

0.1.96

4 years ago

0.1.94

4 years ago

0.1.95

4 years ago

0.1.93

4 years ago

0.1.92

4 years ago

0.1.90

4 years ago

0.1.91

4 years ago

0.1.89

4 years ago

0.1.88

4 years ago

0.1.87

4 years ago

0.1.86

4 years ago

0.1.85

4 years ago

0.1.84

4 years ago

0.1.83

4 years ago

0.1.82

4 years ago

0.1.81

4 years ago

0.1.80

4 years ago

0.1.79

4 years ago

0.1.78

4 years ago

0.1.77

4 years ago

0.1.76

4 years ago

0.1.75

4 years ago

0.1.74

4 years ago

0.1.73

4 years ago

0.1.72

4 years ago

0.1.71

4 years ago

0.1.70

4 years ago

0.1.69

4 years ago

0.1.67

4 years ago

0.1.68

4 years ago

0.1.66

4 years ago

0.1.65

4 years ago

0.1.64

4 years ago

0.1.63

4 years ago

0.1.62

4 years ago

0.1.61

4 years ago

0.1.59

4 years ago

0.1.58

5 years ago

0.1.57

5 years ago

0.1.56

5 years ago

0.1.55

5 years ago

0.1.54

5 years ago

0.1.53

5 years ago

0.1.52

5 years ago

0.1.51

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago