2 min read

SlidingPanel

SlidingPanel

This component allows for any other component or element inside it to be horizontally navigable. It also implements customizable buttons as well as other minor customizations to its general behavior.

Additionally, this component exposes the following props to modify the classes of the elements: buttonClass.

Props

Name Description Type Default
scrollFactor Scroll factor that will dictate how much the scroll moves when pressing a navigation button. number 0.7
showButtons Would make the navigation buttons visible when they're needed or always hide them. boolean true
resetOnContentChange When true, whenever the DOM content in the sliding panel slot changes, it will reset
the scroll position to 0.
boolean true

Slots

Name Description Bindings
(name - type - description)
sliding-panel-left-button Left button content None
default (Required) Sliding panel content None
sliding-panel-right-button Right button content None

Events

This component emits no events.

See it in action

Simplest implementation of the component, just a list-based component inside its slot.

<template>
  <SlidingPanel>
    <div class="item">Item 1</div>
    <div class="item">Item 2</div>
    <div class="item">Item 3</div>
    <div class="item">Item 4</div>
  </SlidingPanel>
</template>
<script>
  import { SlidingPanel } from '@empathyco/x-components';
  export default {
    name: 'SlidingPanelDemo',
    components: {
      SlidingPanel
    }
  };
</script>
<style>
  .x-sliding-panel {
    width: 200px;
  }
  .item {
    display: inline-block;
    width: 100px;
  }
</style>

Play with props

Modifying scroll buttons travel distance

Edit how much the scroll travels when navigating with the buttons by changing the scrollFactor prop.

<template>
  <SlidingPanel :scrollFactor="1.5">
    <div class="item">Item 1</div>
    <div class="item">Item 2</div>
    <div class="item">Item 3</div>
    <div class="item">Item 4</div>
  </SlidingPanel>
</template>
<script>
  import { SlidingPanel } from '@empathyco/x-components';
  export default {
    name: 'SlidingPanelDemo',
    components: {
      SlidingPanel
    }
  };
</script>
<style>
  .x-sliding-panel {
    width: 200px;
  }
  .item {
    display: inline-block;
    width: 100px;
  }
</style>

Hiding scroll buttons

Hide the navigational buttons completely by setting the showButtons prop to false. This is intended to be used when other scrolling options are available, like in mobile, where you can scroll just by swiping.

<template>
  <SlidingPanel :showButtons="false">
    <div class="item">Item 1</div>
    <div class="item">Item 2</div>
    <div class="item">Item 3</div>
    <div class="item">Item 4</div>
  </SlidingPanel>
</template>
<script>
  import { SlidingPanel } from '@empathyco/x-components';
  export default {
    name: 'SlidingPanelDemo',
    components: {
      SlidingPanel
    }
  };
</script>
<style>
  .x-sliding-panel {
    width: 200px;
  }
  .item {
    display: inline-block;
    width: 100px;
  }
</style>

Customizing the content with classes

The buttonClass prop can be used to add classes to the buttons.

The scrollContainerClass prop can be used to add classes to the scroll content.

<template>
  <SlidingPanel buttonClass="x-button--round" scrollContainerClass="x-sliding-panel-fade">
    <div class="item">Item 1</div>
    <div class="item">Item 2</div>
    <div class="item">Item 3</div>
    <div class="item">Item 4</div>
  </SlidingPanel>
</template>
<script>
  import { SlidingPanel } from '@empathyco/x-components';
  export default {
    name: 'SlidingPanelDemo',
    components: {
      SlidingPanel
    }
  };
</script>
<style>
  .x-sliding-panel {
    width: 200px;
  }
  .item {
    display: inline-block;
    width: 100px;
  }
</style>

Disabling reset the scroll when content changes

By default, whenever the content of the sliding panel changes, it auto resets its scroll position. You can disable this behavior setting the resetOnContentChange prop to false.

<template>
  <div>
    <button @click="items++">Add item</button>
    <label>
      <input type="checkbox" v-model="resetOnContentChange" />
      Reset content onchange
    </label>
    <SlidingPanel :resetOnContentChange="resetOnContentChange">
      <div class="item" v-for="item in items" :key="item">Item {{ item }}</div>
    </SlidingPanel>
  </div>
</template>
<script>
  import { SlidingPanel } from '@empathyco/x-components';
  export default {
    name: 'SlidingPanelDemo',
    components: {
      SlidingPanel
    },
    data() {
      return {
        items: 4,
        resetOnContentChange: false
      };
    }
  };
</script>
<style>
  .x-sliding-panel {
    width: 200px;
  }
  .item {
    display: inline-block;
    width: 100px;
  }
</style>

Extending the component

Overriding Button content

By default the buttons show an arrow depicting the direction the scroll would go to when clicked, but this content can be customized with anything, from characters to SVG and images.

<template>
  <SlidingPanel>
    <template #sliding-panel-left-button>Left</template>
    <template #default>
      <div class="item">Item 1</div>
      <div class="item">Item 2</div>
      <div class="item">Item 3</div>
      <div class="item">Item 4</div>
    </template>
    <template #sliding-panel-right-button>Right</template>
  </SlidingPanel>
</template>
<script>
  import { SlidingPanel } from '@empathyco/x-components';
  export default {
    name: 'SlidingPanelDemo',
    components: {
      SlidingPanel
    }
  };
</script>
<style>
  .x-sliding-panel {
    width: 200px;
  }
  .item {
    display: inline-block;
    width: 100px;
  }
</style>