rails_notion_like_multiselect 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eba5478c36b1c52c1ad52b5b3fecb134f13f129a7fb73528f0df01f1a3a088ba
4
+ data.tar.gz: 20d97d8df49ddcb71b1b773959cd3f863b784bea06343b20b2ea5b33ee0eae2c
5
+ SHA512:
6
+ metadata.gz: 84346ab6b7bf5a8389e89abb6a6b1660837c3da90a48e0dd34045f110fc841a0f63e80a205d75996f51dc7288668ab02e3a2f57652e8f0e3f13de02696966161
7
+ data.tar.gz: 95fed342d1ff2045deec03ec2e2c292284e26ce1108fd37f05dc41fd01f87c3c4147a1e63bc1bb6d880dd4762a7fda721aae7838b23984620effc71e61359b05
data/CHANGELOG.md ADDED
@@ -0,0 +1,60 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.1] - 2025-09-25
9
+
10
+ ### Fixed
11
+ - Fixed install generator template path issue
12
+ - Resolved gemspec warnings with proper version constraints
13
+ - Updated GitHub repository URL to pageinteract organization
14
+ - Fixed create new item functionality to capture full text instead of first character
15
+ - Added newly created items to dropdown with selected state
16
+ - Improved dark mode support and theme handling
17
+
18
+ ### Changed
19
+ - Updated Rails dependency to support versions 7.0 through 8.x
20
+ - Set Tailwind CSS dependency specifically to version 4.x
21
+ - Improved SVG rendering for close buttons on badges
22
+ - Enhanced ID comparison for consistent string handling
23
+
24
+ ## [0.1.0] - 2025-09-25
25
+
26
+ ### Added
27
+ - Initial release of Rails Notion-Like Multiselect gem
28
+ - Beautiful, keyboard-navigable multiselect component inspired by Notion's UI/UX
29
+ - Full keyboard navigation support (Arrow keys, Enter, Escape, Tab, Backspace)
30
+ - Real-time search and filtering capabilities
31
+ - Create new items inline with optional API endpoint support
32
+ - Theme support (light, dark, auto modes)
33
+ - Customizable badge colors (blue, green, purple, yellow, red)
34
+ - Smart selection display with compact badges
35
+ - Fully responsive design
36
+ - Proper ARIA attributes for accessibility
37
+ - Built with Hotwire Stimulus for modern Rails applications
38
+ - Tailwind CSS v4 styling with automatic dark mode adaptation
39
+ - Support for Rails 7.0+ applications
40
+ - Comprehensive helper methods for easy integration
41
+ - Installation generator for quick setup
42
+
43
+ ### Features
44
+ - Multiselect field helper for Rails forms
45
+ - Dynamic item creation with "Create" option
46
+ - Persistent selections across form submissions
47
+ - Server-side item creation with API endpoint support
48
+ - Automatic ID management for created items
49
+ - Visual feedback for selected items in dropdown
50
+ - Smooth keyboard navigation with highlighting
51
+ - Click outside to close dropdown
52
+ - Empty state handling
53
+ - Customizable placeholder and help text
54
+
55
+ ### Technical
56
+ - MIT License
57
+ - Ruby 3.0+ required
58
+ - Rails 7.0+ required
59
+ - Stimulus.js required
60
+ - Tailwind CSS required (via tailwindcss-rails gem)
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Sulman Baig
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,388 @@
1
+ # Rails Notion-Like Multiselect
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rails_notion_like_multiselect.svg)](https://badge.fury.io/rb/rails_notion_like_multiselect)
4
+ [![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.txt)
5
+
6
+ A beautiful, keyboard-navigable multiselect component for Rails applications, inspired by Notion's elegant UI/UX. This gem provides a fully-featured multiselect input with search, filtering, and the ability to create new items on the fly.
7
+
8
+ ![Rails Notion-Like Multiselect Demo](demo.gif)
9
+
10
+ ## Features
11
+
12
+ - 🎨 **Beautiful Notion-inspired UI** - Clean, modern design that fits seamlessly into any application
13
+ - ⌨️ **Full keyboard navigation** - Arrow keys, Enter, Escape, Tab, and Backspace support
14
+ - 🔍 **Real-time search/filtering** - Quickly find items as you type
15
+ - ➕ **Create new items** - Optional ability to create new items inline
16
+ - 🎯 **Smart selection display** - Selected items appear as compact badges inside the input
17
+ - 🌈 **Customizable colors** - Multiple badge color options (blue, green, purple, yellow, red)
18
+ - 🌓 **Dark mode support** - Automatically adapts to light and dark themes
19
+ - 📱 **Fully responsive** - Works great on mobile and desktop
20
+ - ♿ **Accessible** - Proper ARIA attributes and keyboard support
21
+ - 🚀 **Stimulus-powered** - Built with Hotwire Stimulus for modern Rails apps
22
+ - 🎨 **Tailwind CSS v4** - Styled with Tailwind CSS v4 for modern, customizable design
23
+
24
+ ## Requirements
25
+
26
+ - Rails 7.0 - 8.x
27
+ - Ruby 3.0+
28
+ - Stimulus.js ~> 1.0 (included as dependency)
29
+ - Tailwind CSS 4.x (included via tailwindcss-rails gem)
30
+
31
+ ## Installation
32
+
33
+ ### From RubyGems (when published)
34
+
35
+ Add this line to your application's Gemfile:
36
+
37
+ ```ruby
38
+ gem 'rails_notion_like_multiselect'
39
+ ```
40
+
41
+ ### From GitHub
42
+
43
+ To use the latest version directly from GitHub, add this to your Gemfile:
44
+
45
+ ```ruby
46
+ gem 'rails_notion_like_multiselect', git: 'https://github.com/pageinteract/rails_notion_like_multiselect.git'
47
+ ```
48
+
49
+ Or to use a specific version/tag:
50
+
51
+ ```ruby
52
+ gem 'rails_notion_like_multiselect', git: 'https://github.com/pageinteract/rails_notion_like_multiselect.git', tag: 'v0.1.1'
53
+ ```
54
+
55
+ Or to use a specific branch:
56
+
57
+ ```ruby
58
+ gem 'rails_notion_like_multiselect', git: 'https://github.com/pageinteract/rails_notion_like_multiselect.git', branch: 'main'
59
+ ```
60
+
61
+ Then execute:
62
+
63
+ ```bash
64
+ bundle install
65
+ ```
66
+
67
+ ## Setup
68
+
69
+ ### Quick Setup
70
+
71
+ After installation, run the generator to set up the component:
72
+
73
+ ```bash
74
+ rails generate rails_notion_like_multiselect:install
75
+ ```
76
+
77
+ This will:
78
+ - Copy the Stimulus controller to your application
79
+ - Register the controller in your Stimulus application
80
+ - Create an initializer with default configuration
81
+
82
+ ### Prerequisites
83
+
84
+ The gem automatically includes `tailwindcss-rails` as a dependency. If you haven't set up Tailwind CSS in your application yet, run:
85
+
86
+ ```bash
87
+ rails tailwindcss:install
88
+ ```
89
+
90
+ This will create the necessary Tailwind configuration files and set up the build process.
91
+
92
+ **Important:** Make sure to include the gem's view paths in your Tailwind configuration to ensure all classes are properly compiled:
93
+
94
+ ```javascript
95
+ // tailwind.config.js
96
+ module.exports = {
97
+ content: [
98
+ './app/**/*.{erb,haml,html,slim,rb}',
99
+ './node_modules/rails_notion_like_multiselect/**/*.{js,rb}',
100
+ // Or if using the gem directly:
101
+ './vendor/bundle/ruby/*/gems/rails_notion_like_multiselect-*/**/*.{js,rb}'
102
+ ],
103
+ // ... rest of your config
104
+ }
105
+ ```
106
+
107
+ ### Manual Setup (if not using generator)
108
+
109
+ #### 1. Import the JavaScript controller
110
+
111
+ In your `app/javascript/controllers/index.js`:
112
+
113
+ ```javascript
114
+ import RailsNotionMultiselectController from "rails_notion_multiselect_controller"
115
+ application.register("rails-notion-multiselect", RailsNotionMultiselectController)
116
+ ```
117
+
118
+ #### 2. Include the helper in your application
119
+
120
+ The helper is automatically included when you install the gem.
121
+
122
+ ## Usage
123
+
124
+ ### Basic Usage
125
+
126
+ In your Rails form:
127
+
128
+ ```erb
129
+ <%= form_with model: @game do |form| %>
130
+ <%= multiselect_field(
131
+ form,
132
+ :category_ids,
133
+ collection: @categories,
134
+ selected: @game.categories,
135
+ placeholder: "Search categories...",
136
+ label: "Categories"
137
+ ) %>
138
+ <% end %>
139
+ ```
140
+
141
+ ### With Create Capability
142
+
143
+ Allow users to create new items on the fly:
144
+
145
+ ```erb
146
+ <%= multiselect_field(
147
+ form,
148
+ :tags,
149
+ collection: @existing_tags,
150
+ selected: @game.tags,
151
+ allow_create: true,
152
+ placeholder: "Search or create tags...",
153
+ label: "Tags",
154
+ help_text: "Type and press Enter to create new tags"
155
+ ) %>
156
+ ```
157
+
158
+ ### With Explicit Theme
159
+
160
+ Force a specific theme regardless of system settings:
161
+
162
+ ```erb
163
+ <%= multiselect_field(
164
+ form,
165
+ :category_ids,
166
+ collection: @categories,
167
+ selected: @game.categories,
168
+ theme: "dark", # Options: "light", "dark", "auto"
169
+ label: "Categories"
170
+ ) %>
171
+ ```
172
+
173
+ ### With Custom Colors
174
+
175
+ Use different badge colors for different types of data:
176
+
177
+ ```erb
178
+ <%= multiselect_field(
179
+ form,
180
+ :category_ids,
181
+ collection: @categories,
182
+ selected: @game.categories,
183
+ badge_color: "green", # Options: blue, green, purple, yellow, red
184
+ label: "Categories"
185
+ ) %>
186
+ ```
187
+
188
+ ### With API Endpoint
189
+
190
+ For server-side creation of new items:
191
+
192
+ ```erb
193
+ <%= multiselect_field(
194
+ form,
195
+ :tags,
196
+ collection: @tags,
197
+ selected: @game.tags,
198
+ allow_create: true,
199
+ api_endpoint: "/api/tags",
200
+ item_type: "tag"
201
+ ) %>
202
+ ```
203
+
204
+ ## Options
205
+
206
+ | Option | Type | Default | Description |
207
+ | -------------- | ------- | ----------------------- | -------------------------------------- |
208
+ | `collection` | Array | `[]` | Array of items to select from |
209
+ | `selected` | Array | `[]` | Currently selected items |
210
+ | `allow_create` | Boolean | `false` | Allow creating new items |
211
+ | `placeholder` | String | `"Search or select..."` | Input placeholder text |
212
+ | `label` | String | Field name | Label for the field |
213
+ | `item_type` | String | Field singularized | Type of items (for create prompt) |
214
+ | `badge_color` | String | `"blue"` | Color scheme for badges |
215
+ | `api_endpoint` | String | `nil` | API endpoint for server-side creation |
216
+ | `help_text` | String | `nil` | Help text below the field |
217
+ | `theme` | String | `"auto"` | Theme mode: "light", "dark", or "auto" |
218
+
219
+ ## Keyboard Shortcuts
220
+
221
+ - **↓/↑** - Navigate through options
222
+ - **Enter** - Select highlighted option or create new item
223
+ - **Escape** - Close dropdown
224
+ - **Backspace** - Remove last selected item (when input is empty)
225
+ - **Tab** - Close dropdown and move to next field
226
+ - **Any character** - Open dropdown and start searching
227
+
228
+ ## Configuration
229
+
230
+ You can configure default settings in an initializer:
231
+
232
+ ```ruby
233
+ # config/initializers/rails_notion_like_multiselect.rb
234
+ RailsNotionLikeMultiselect.setup do |config|
235
+ config.default_badge_color = "green"
236
+ config.default_placeholder = "Type to search..."
237
+ config.enable_keyboard_navigation = true
238
+ end
239
+ ```
240
+
241
+ ## Styling
242
+
243
+ The component is built with Tailwind CSS v4 and uses its utility classes for styling. The gem requires Tailwind CSS v4 to be properly installed in your Rails application for the component to render correctly.
244
+
245
+ ### Dark Mode Support
246
+
247
+ The multiselect component supports three theme modes:
248
+
249
+ - **`"auto"` (default)**: Automatically adapts to your application's dark mode settings using Tailwind's dark mode classes
250
+ - **`"light"`**: Forces light theme styling regardless of system settings
251
+ - **`"dark"`**: Forces dark theme styling regardless of system settings
252
+
253
+ Theme behaviors:
254
+ - **Light mode**: Light colored badges with dark text, white background
255
+ - **Dark mode**: Dark colored badges with light text, dark background
256
+ - **Automatic contrast**: All elements adjust for optimal readability
257
+
258
+ To enable dark mode in your application, configure Tailwind CSS:
259
+
260
+ ```javascript
261
+ // tailwind.config.js
262
+ module.exports = {
263
+ darkMode: 'class', // or 'media' for system preference
264
+ // ... rest of your config
265
+ }
266
+ ```
267
+
268
+ ### Custom Styling
269
+
270
+ If you need to customize the styles, you can override these classes in your Tailwind configuration or target them directly:
271
+
272
+ - `.rails-notion-multiselect-container` - Main container
273
+ - `.rails-notion-multiselect-input` - Input field
274
+ - `.rails-notion-multiselect-badge` - Selected item badges
275
+ - `.rails-notion-multiselect-dropdown` - Dropdown container
276
+ - `.rails-notion-multiselect-option` - Individual options
277
+
278
+ ## Examples
279
+
280
+ ### Categories with Predefined Options
281
+
282
+ ```erb
283
+ <%= multiselect_field(
284
+ form,
285
+ :category_ids,
286
+ collection: Category.active.ordered,
287
+ selected: @product.categories,
288
+ placeholder: "Select categories...",
289
+ label: "Product Categories",
290
+ badge_color: "blue",
291
+ help_text: "Choose all applicable categories"
292
+ ) %>
293
+ ```
294
+
295
+ ### Tags with Creation
296
+
297
+ ```erb
298
+ <%= multiselect_field(
299
+ form,
300
+ :tags,
301
+ collection: ["Ruby", "Rails", "JavaScript", "React", "Vue"],
302
+ selected: @post.tags || [],
303
+ allow_create: true,
304
+ placeholder: "Add tags...",
305
+ label: "Post Tags",
306
+ badge_color: "green",
307
+ item_type: "tag",
308
+ help_text: "Select existing tags or create new ones"
309
+ ) %>
310
+ ```
311
+
312
+ ### Users Assignment
313
+
314
+ ```erb
315
+ <%= multiselect_field(
316
+ form,
317
+ :assigned_user_ids,
318
+ collection: User.active.map { |u| { id: u.id, name: u.full_name } },
319
+ selected: @task.assigned_users,
320
+ placeholder: "Assign team members...",
321
+ label: "Assigned To",
322
+ badge_color: "purple"
323
+ ) %>
324
+ ```
325
+
326
+ ## Controller Actions
327
+
328
+ If you're using the `api_endpoint` option for server-side creation, implement a controller action like:
329
+
330
+ ```ruby
331
+ class TagsController < ApplicationController
332
+ def create
333
+ tag = Tag.find_or_create_by(name: params[:tag][:name])
334
+ render json: { id: tag.id, name: tag.name }
335
+ end
336
+ end
337
+ ```
338
+
339
+ ## Browser Support
340
+
341
+ - Chrome (latest)
342
+ - Firefox (latest)
343
+ - Safari (latest)
344
+ - Edge (latest)
345
+
346
+ ## Development
347
+
348
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
349
+
350
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
351
+
352
+ ## Contributing
353
+
354
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pageinteract/rails_notion_like_multiselect. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
355
+
356
+ ### How to Contribute
357
+
358
+ 1. Fork the repository
359
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
360
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
361
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
362
+ 5. Open a Pull Request
363
+
364
+ ## License
365
+
366
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
367
+
368
+ ### Note on Tailwind CSS Usage
369
+
370
+ This gem uses only open-source Tailwind CSS utility classes. No Tailwind UI/Plus components or proprietary code are used in this implementation. All styling is created using the freely available Tailwind CSS framework under the MIT license.
371
+
372
+ ## Acknowledgments
373
+
374
+ - Inspired by [Notion](https://notion.so)'s excellent multiselect component
375
+ - Built with [Stimulus](https://stimulus.hotwired.dev/) for modern Rails applications
376
+ - Styled with [Tailwind CSS](https://tailwindcss.com/) for beautiful, responsive design
377
+
378
+ ## Author
379
+
380
+ **Sulman Baig**
381
+ - GitHub: [@sulmanweb](https://github.com/sulmanweb)
382
+ - Email: sulmanweb@gmail.com
383
+
384
+ ## Dependencies
385
+
386
+ - [Rails](https://rubyonrails.org/) - MIT License
387
+ - [Stimulus](https://stimulus.hotwired.dev/) - MIT License
388
+ - [Tailwind CSS](https://tailwindcss.com/) - MIT License (via tailwindcss-rails gem)
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]