项目作者: unlight

项目描述 :
Tailwind plugin to add floating label, control with float label components
高级语言: HTML
项目地址: git://github.com/unlight/tailwind-float-label.git
创建时间: 2020-10-10T16:01:32Z
项目社区:https://github.com/unlight/tailwind-float-label

开源协议:MIT License

下载


tailwind-float-label

Tailwind plugin to add floating label, control with float label components

Demo - https://unlight.github.io/tailwind-float-label

Setup

  1. npm install --save-dev tailwind-float-label

Add plugin to plugins section of tailwind.config.js

  1. plugins: [require('tailwind-float-label')(options)],

Options

  1. type Options = {
  2. /**
  3. * Custom styles for container.
  4. */
  5. container?: DeepPartial<{ [k: string]: string } | string>;
  6. /**
  7. * Custom styles for input control.
  8. */
  9. control?: DeepPartial<{ [k: string]: string } | string>;
  10. /**
  11. * Custom styles for label.
  12. */
  13. label?: DeepPartial<{ [k: string]: string } | string>;
  14. };

Usage

Plugins adds these components supposed used together:

  • .float-label-container Container which holds input control and label
  • .float-label-control Form control
  • .float-label-self Label
  • .float-label-sticky Label which is always visible
  • But .float-label-auto Automatically make label floating and input inside this container
  1. <form class="max-w-xs mx-auto p-5 space-y-4">
  2. <h2 class="text-2xl font-bold text-center">Example</h2>
  3. <div class="float-label-container">
  4. <input
  5. type="text"
  6. id="name"
  7. autocomplete="off"
  8. placeholder="Name"
  9. class="float-label-control outline-none focus:shadow-outline border w-full px-1"
  10. />
  11. <label for="name" class="float-label-self bg-white text-gray-500">Name</label>
  12. </div>
  13. <!-- Auto: make `label` floating for `input` -->
  14. <div class="float-label-auto">
  15. <input
  16. type="text"
  17. id="auto"
  18. autocomplete="off"
  19. placeholder="Auto"
  20. class="outline-none focus:shadow-outline border w-full px-1"
  21. />
  22. <label for="auto" class="bg-white text-gray-500">Auto</label>
  23. </div>
  24. </form>

Notes:

.float-label-control and .float-label-self must be direct children of .float-label-container

Similar Projects

Resources