daisy_components 0.1.0

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.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.cursor/rules/how-to-write-tests.mdc +67 -0
  3. data/.cursor/rules/preview-file-stucture.mdc +95 -0
  4. data/.cursorrules +64 -0
  5. data/.github/dependabot.yml +12 -0
  6. data/.github/workflows/ci.yml +65 -0
  7. data/.gitignore +13 -0
  8. data/.vscode/launch.json +55 -0
  9. data/.vscode/settings.json +44 -0
  10. data/CHANGELOG.md +39 -0
  11. data/Gemfile +32 -0
  12. data/Gemfile.lock +335 -0
  13. data/MIT-LICENSE +20 -0
  14. data/README.md +64 -0
  15. data/Rakefile +7 -0
  16. data/app/assets/images/daisy_components/.keep +0 -0
  17. data/app/assets/stylesheets/daisy_ui/application.css +15 -0
  18. data/app/components/daisy_ui/actions/button.rb +262 -0
  19. data/app/components/daisy_ui/actions/dropdown.rb +125 -0
  20. data/app/components/daisy_ui/actions/swap.rb +126 -0
  21. data/app/components/daisy_ui/base_component.rb +29 -0
  22. data/app/components/daisy_ui/data_display/accordion.rb +128 -0
  23. data/app/components/daisy_ui/data_display/accordion_item.rb +121 -0
  24. data/app/components/daisy_ui/data_display/avatar.rb +131 -0
  25. data/app/components/daisy_ui/data_display/avatar_group.rb +102 -0
  26. data/app/components/daisy_ui/data_display/badge.rb +126 -0
  27. data/app/components/daisy_ui/data_display/card/actions.rb +94 -0
  28. data/app/components/daisy_ui/data_display/card/body.rb +113 -0
  29. data/app/components/daisy_ui/data_display/card/figure.rb +44 -0
  30. data/app/components/daisy_ui/data_display/card/title.rb +56 -0
  31. data/app/components/daisy_ui/data_display/card.rb +157 -0
  32. data/app/components/daisy_ui/data_display/chat.rb +92 -0
  33. data/app/components/daisy_ui/data_display/chat_bubble/metadata.rb +71 -0
  34. data/app/components/daisy_ui/data_display/chat_bubble.rb +166 -0
  35. data/app/components/daisy_ui/divider.rb +9 -0
  36. data/app/components/daisy_ui/item.rb +20 -0
  37. data/app/components/daisy_ui/title.rb +9 -0
  38. data/app/controllers/concerns/.keep +0 -0
  39. data/app/controllers/daisy_ui/application_controller.rb +6 -0
  40. data/app/helpers/daisy_ui/application_helper.rb +6 -0
  41. data/app/helpers/daisy_ui/icons_helper.rb +296 -0
  42. data/app/views/layouts/daisyui/application.html.erb +17 -0
  43. data/bin/parse_coverage.rb +59 -0
  44. data/bin/rails +57 -0
  45. data/bin/rubocop +10 -0
  46. data/bin/scrape_component +86 -0
  47. data/daisy_components.gemspec +33 -0
  48. data/docs/assets/2025-01_screeshot_1.png +0 -0
  49. data/docs/assets/2025-01_screeshot_2.png +0 -0
  50. data/docs/assets/2025-01_screeshot_3.png +0 -0
  51. data/lib/daisy_components.rb +5 -0
  52. data/lib/daisy_ui/engine.rb +51 -0
  53. data/lib/daisy_ui/version.rb +5 -0
  54. data/lib/daisy_ui.rb +13 -0
  55. data/lib/tasks/daisy_ui_tasks.rake +6 -0
  56. metadata +112 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 94632f364daea5f4df1e9d643d2c3d52497094864a56e94a0633fa34cba2eef9
4
+ data.tar.gz: e0236bc53bb5b9ce09b06f9b3be694b7c7c12b153a6896c30b51a607a0bac2a0
5
+ SHA512:
6
+ metadata.gz: ae5549f8d75c398aa130afda738e6256bbdfa52d5400f6dd07ed77abcc623b430c8a459e1882eeb3d4636fe4cd5d9d37a8b1a27d76ac86534c6c887c953fe564
7
+ data.tar.gz: 2ebbc7564a8f45f4c3a35ae60e33980b0cfc93b5a177221f2bb9baab8801c140931e72d0ef09a4df3c3e4d347a7129f5216c7749b1370cdf5489107203c97baa
@@ -0,0 +1,67 @@
1
+ ---
2
+ description:
3
+ globs:
4
+ alwaysApply: false
5
+ ---
6
+ # Component Testing Structure
7
+
8
+ ## Overview
9
+ Each component should have automated tests that verify both the component behavior and its preview examples. The `PreviewTestConcern` provides automated testing of all preview examples against their corresponding fixtures.
10
+
11
+ ## Basic Test Structure
12
+ ```ruby
13
+ module DaisyComponents
14
+ module DataDisplay
15
+ class CardComponentTest < DaisyComponents::ComponentTestCase
16
+ include DaisyComponents::PreviewTestConcern
17
+
18
+ # Test all preview examples automatically
19
+ test_all_preview_examples(
20
+ preview_class: CardComponentPreview,
21
+ component_name: 'card',
22
+ exclude: ['playground'] # Optional: exclude specific examples
23
+ )
24
+
25
+
26
+ # Additional component-specific tests...
27
+ def test_complex_method
28
+ #...
29
+ end
30
+ end
31
+ end
32
+ end
33
+ ```
34
+
35
+ ## What Gets Tested
36
+ 1. All preview methods (except playground) are automatically tested
37
+ 2. Each preview's rendered output is compared against its fixture
38
+ 3. HTML is normalized before comparison (classes, attributes, whitespace)
39
+ 4. Failures indicate either:
40
+ - Missing fixture file
41
+ - Mismatch between preview output and fixture
42
+
43
+ ## Test Organization
44
+ - Test files: `test/components/daisy_ui/<module>/<component_name>_test.rb`
45
+ - Fixtures: `test/fixtures/components/<component_name>/<example_name>.html`
46
+ - NO: test files inside test/components/previews
47
+
48
+ ## Best Practices
49
+ 1. Always include `PreviewTestConcern`
50
+ 2. Use `test_all_preview_examples` for comprehensive coverage
51
+ 3. Add component-specific tests for behavior not covered by previews
52
+ 4. Keep fixtures up to date with component changes
53
+ 5. Don't duplicate preview tests unnecessarily
54
+ 6. Give precedence to preview tests for visual examples
55
+ 7. Focus component tests on behavior and edge cases
56
+
57
+ ## Coverage Checking
58
+ ```bash
59
+ # Run tests with coverage
60
+ COVERAGE=true bin/rails test
61
+
62
+ # Parse coverage report
63
+ ./bin/parse_coverage.rb
64
+ ```
65
+ ```
66
+
67
+ This rule provides a clear structure for how component testing should be set up and what gets tested automatically through the `PreviewTestConcern`.
@@ -0,0 +1,95 @@
1
+ ---
2
+ description:
3
+ globs:
4
+ alwaysApply: true
5
+ ---
6
+ # Preview File Structurex
7
+ ## Overview
8
+ Each preview file corresponds to a DaisyUI component and includes examples that match DaisyUI's documentation. The examples are tested against HTML fixtures that are scraped from the actual rendered output.
9
+
10
+ ## File Organization
11
+ - Preview files: `test/components/previews/daisy_ui/`
12
+ - Fixture files: `test/fixtures/components/<component_name>/`
13
+ - Each preview method has a corresponding fixture file
14
+
15
+ ## Preview Class Structure
16
+
17
+ ### Header
18
+ ```ruby
19
+ # @label ComponentName
20
+ module DaisyComponents
21
+ module Actions
22
+ class ComponentNamePreview < ViewComponent::Preview
23
+ include DaisyComponents::IconsHelper # if icons needed
24
+ ```
25
+
26
+ ### Playground Section
27
+ 1. Must start with `# @!group Playground`
28
+ 2. Interactive playground with all possible parameters
29
+ 3. Must end with `# @!endgroup`
30
+ ## DaisyUI Example Methods
31
+ - Each method corresponds to a DaisyUI example from DaisyUI's documentation
32
+ - Two main patterns for rendering:
33
+
34
+ 1. Direct Component Rendering (Preferred for single component examples):
35
+ ```ruby
36
+ # Card with custom color
37
+ # ---------------
38
+ # Card with primary background color
39
+ def card_with_custom_color
40
+ render CardComponent.new(
41
+ title: 'Card title!',
42
+ description: 'Some description',
43
+ button: { text: 'Buy Now', justify: :end },
44
+ color: :primary
45
+ )
46
+ end
47
+ ```
48
+
49
+ 2. Template Rendering (For multiple components or complex layouts):
50
+ ```ruby
51
+ # Button Sizes
52
+ # ---------------
53
+ # Different button size variations
54
+ def button_sizes
55
+ render_with_template
56
+ end
57
+ ```
58
+
59
+ ## Fixtures
60
+ - Location: `test/fixtures/components/<component_name>/`
61
+ - Naming: Must match preview method name (e.g. `active_buttons.html`)
62
+ - Content: Contains the expected HTML output
63
+ - Used by `PreviewTestConcern` to verify preview rendering
64
+ - Example:
65
+ ```html
66
+ <button class="btn btn-active" type="button">Default</button>
67
+ ```
68
+
69
+ ## Testing
70
+ - Uses `PreviewTestConcern` to automatically test all examples
71
+ - Compares rendered preview output with fixture files
72
+ - Normalizes HTML for consistent comparison
73
+ - Example:
74
+ ```ruby
75
+ test_all_preview_examples(
76
+ preview_class: ButtonComponentPreview,
77
+ component_name: 'button',
78
+ exclude: ['playground']
79
+ )
80
+ ```
81
+ ### Template Organization
82
+ - Template files should be in: `test/components/previews/daisy_ui/<module>/<component_name>_preview/`
83
+ - Template names should match method names (e.g. `button_sizes.html.erb`)
84
+ - Example path: `test/components/previews/daisy_ui/actions/button_component_preview/button_sizes.html.erb`
85
+
86
+
87
+ ## Best Practices
88
+ 1. Use direct component rendering when possible (clearer and more maintainable)
89
+ 2. Use template rendering for:
90
+ - Multiple component variations (like sizes, colors)
91
+ - Complex layouts
92
+ - Examples requiring custom HTML structure
93
+ 4. Pass helpers via locals if needed: `render_with_template(locals: { helper: self }
94
+
95
+
data/.cursorrules ADDED
@@ -0,0 +1,64 @@
1
+ The goal of this project is to create a component library.
2
+ The design system is providered by DaisyUI.
3
+ The Component Library is a Rails Engine.
4
+ It's build with TailwindCSS and DaisyUI, ViewComponent and Rails.
5
+
6
+
7
+ We are using tailwindcss for this reason we can't use composed classes with strings interpolation.
8
+
9
+
10
+
11
+ We take inspiration from the following projects:
12
+ https://github.com/primer/design
13
+ https://github.com/primer/view_components
14
+
15
+ This project use Lookbook for documentation
16
+ https://github.com/lookbook-hq/lookbook
17
+ The preview are in the test/components/previews folder
18
+ The docs are in the test/components/docs folder
19
+
20
+ use Gemfile to manage dependencies no gemspec
21
+
22
+ Use Minitest and Fixtures for testing
23
+ Use Capybara for testing
24
+
25
+ Create SVG for icons, and use the IconHelper to render them
26
+ The IconHelper should not be used in the component, but in the test and the preview, Icon are passed, to the component
27
+
28
+ DONT delete documentation comments in the code, update them instead
29
+
30
+ Ruby Style Guide
31
+ Style/ClassAndModuleChildren
32
+
33
+ good:
34
+ ```ruby
35
+ module DaisyUI
36
+ module Actions
37
+ class SwapComponentTest < DaisyUI::ComponentTestCase
38
+ end
39
+ end
40
+ end
41
+ ```
42
+
43
+ bad:
44
+ ```ruby
45
+ class DaisyComponents::SwapComponentTest < DaisyComponents::ComponentTestCase
46
+ end
47
+ ```
48
+
49
+ Every component preview should have a playground method with all the parameters as options and the description as Lookbook description.
50
+ For every component create:
51
+ - Ruy class with the inizializer documented with YARD doc
52
+ - html template
53
+ - lookbook preview with a playground method and the description as Lookbook description with group and label
54
+ - TEST: in the test we test the component behavior and the preview (just the fact that they render). Don't duplicate tests to much, but give precedence to the preview but be sure to test the behavior)
55
+ - documentation
56
+
57
+ For images, use picsum.photos/ to generate placeholder images.
58
+
59
+ When you want to check the coverage, run:
60
+ COVERAGE=true bin/rails test
61
+ Read the coverage report by using ./bin/parse_coverage.rb
62
+
63
+ Every component preview should be organized into groups that separate HTML and Ruby source rendering.
64
+
@@ -0,0 +1,12 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 10
8
+ - package-ecosystem: github-actions
9
+ directory: "/"
10
+ schedule:
11
+ interval: daily
12
+ open-pull-requests-limit: 10
@@ -0,0 +1,65 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches: [ main ]
7
+
8
+ jobs:
9
+ lint:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: Checkout code
13
+ uses: actions/checkout@v4
14
+
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ruby-3.4.1
19
+ bundler-cache: true
20
+
21
+ - name: Lint code for consistent style
22
+ run: bin/rubocop
23
+
24
+ test:
25
+ runs-on: ubuntu-latest
26
+
27
+ # services:
28
+ # redis:
29
+ # image: redis
30
+ # ports:
31
+ # - 6379:6379
32
+ # options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
33
+ steps:
34
+ - name: Install packages
35
+ run: sudo apt-get update && sudo apt-get install --no-install-recommends -y build-essential git pkg-config google-chrome-stable
36
+
37
+ - name: Checkout code
38
+ uses: actions/checkout@v4
39
+
40
+ - name: Set up Ruby
41
+ uses: ruby/setup-ruby@v1
42
+ with:
43
+ ruby-version: ruby-3.4.1
44
+ bundler-cache: true
45
+
46
+ - name: Run tests
47
+ env:
48
+ RAILS_ENV: test
49
+ COVERAGE: true
50
+ # REDIS_URL: redis://localhost:6379/0
51
+ run: bin/rails test
52
+
53
+ - name: Upload coverage reports to Codecov
54
+ uses: codecov/codecov-action@v5
55
+ with:
56
+ token: ${{ secrets.CODECOV_TOKEN }}
57
+
58
+ - name: Keep screenshots from failed system tests
59
+ uses: actions/upload-artifact@v4
60
+ if: failure()
61
+ with:
62
+ name: screenshots
63
+ path: ${{ github.workspace }}/tmp/screenshots
64
+ if-no-files-found: ignore
65
+
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /doc/
3
+ /log/*.log
4
+ /pkg/
5
+ /tmp/
6
+ /test/dummy/log/*.log
7
+ /test/dummy/storage/
8
+ /test/dummy/tmp/
9
+
10
+ .DS_Store
11
+ .env*
12
+ coverage/
13
+ .idea/
@@ -0,0 +1,55 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "type": "ruby_lsp",
6
+ "name": "Debug Rails",
7
+ "request": "launch",
8
+ "program": "${workspaceRoot}/bin/rails",
9
+ "args": ["server"],
10
+ "useBundler": true,
11
+ "env": {
12
+ "RAILS_ENV": "development"
13
+ }
14
+ },
15
+ {
16
+ "type": "ruby_lsp",
17
+ "name": "Debug Test File",
18
+ "request": "launch",
19
+ "program": "ruby -Itest ${relativeFile}",
20
+ "useBundler": true,
21
+ "env": {
22
+ "RAILS_ENV": "test"
23
+ }
24
+ },
25
+ {
26
+ "type": "ruby_lsp",
27
+ "name": "Run Test with Coverage",
28
+ "request": "launch",
29
+ "program": "ruby -Itest ${relativeFile}",
30
+ "useBundler": true,
31
+ "env": {
32
+ "RAILS_ENV": "test",
33
+ "COVERAGE": "true"
34
+ }
35
+ },
36
+ {
37
+ "type": "ruby_lsp",
38
+ "name": "Run All Tests with Coverage",
39
+ "request": "launch",
40
+ "program": "${workspaceRoot}/bin/rails",
41
+ "args": ["test"],
42
+ "useBundler": true,
43
+ "env": {
44
+ "RAILS_ENV": "test",
45
+ "COVERAGE": "true"
46
+ }
47
+ },
48
+ {
49
+ "type": "ruby_lsp",
50
+ "request": "attach",
51
+ "name": "Attach to Process",
52
+ "port": 1234
53
+ }
54
+ ]
55
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ // "ruby.useLanguageServer": true,
3
+ // "ruby.lint": {
4
+ // "rubocop": true
5
+ // },
6
+ // "ruby.format": "rubocop",
7
+ // "ruby.intellisense": "rubyLocate",
8
+ "[ruby]": {
9
+ "editor.formatOnSave": true,
10
+ "editor.defaultFormatter": "Shopify.ruby-lsp",
11
+ "editor.semanticHighlighting.enabled": true,
12
+ },
13
+ "[erb]": {
14
+ "editor.formatOnSave": true,
15
+ "editor.defaultFormatter": "Shopify.ruby-lsp",
16
+ "editor.semanticHighlighting.enabled": true
17
+ },
18
+ "rubyLsp.enabledFeatures": {
19
+ "codeActions": true,
20
+ "diagnostics": true,
21
+ "documentHighlights": true,
22
+ "documentLink": true,
23
+ "documentSymbols": true,
24
+ "foldingRanges": true,
25
+ "formatting": true,
26
+ "hover": true,
27
+ "inlayHint": true,
28
+ "onTypeFormatting": true,
29
+ "selectionRanges": true,
30
+ "semanticHighlighting": true,
31
+ "completion": true,
32
+ "codeLens": true,
33
+ "definition": true,
34
+ "workspaceSymbol": true
35
+ },
36
+ "rubyLsp.formatter": "auto",
37
+ "rubyLsp.rubyVersionManager": {
38
+ "identifier": "mise"
39
+ },
40
+ "files.associations": {
41
+ "*.erb": "erb",
42
+ "*.html.erb": "erb"
43
+ }
44
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,39 @@
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.0] - 2024-12-19
9
+
10
+ ### Added
11
+ - Initial release of DaisyUI Components for Rails
12
+ - Rails Engine with ViewComponent integration
13
+ - TailwindCSS and DaisyUI support
14
+ - Base component architecture
15
+ - Components:
16
+ - Actions
17
+ - Button
18
+ - Dropdown
19
+ - Swap
20
+ - Data Display
21
+ - Accordion
22
+ - Avatar
23
+ - Avatar Group
24
+ - Badge
25
+ - Card
26
+ - Chat
27
+ - Lookbook integration for component documentation
28
+ - Comprehensive test suite with Minitest and Capybara
29
+ - Icon helper system (to be improved)
30
+
31
+ ### Features
32
+ - ViewComponent-based architecture
33
+ - DaisyUI design system integration
34
+ - Lookbook documentation
35
+ - Comprehensive testing framework
36
+ - Rails 8.0+ compatibility
37
+ - Ruby 3.4+ support
38
+
39
+ [0.1.0]: https://github.com/Nittarab/daisy_components/releases/tag/v0.1.0
data/Gemfile ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'puma'
8
+ gem 'redcarpet', '3.6.1'
9
+ gem 'view_component', '3.21.0'
10
+
11
+ group :development do
12
+ gem 'lookbook', '2.3.4'
13
+ gem 'rubocop', '1.71.0'
14
+ gem 'rubocop-capybara', '2.21.0'
15
+ gem 'rubocop-performance', '1.23.1'
16
+ gem 'rubocop-rails', '2.29.1'
17
+ gem 'ruby-lsp'
18
+ gem 'ruby-lsp-rails'
19
+ end
20
+
21
+ group :test do
22
+ gem 'capybara'
23
+ gem 'debug'
24
+ gem 'simplecov', require: false
25
+ gem 'simplecov-cobertura', require: false
26
+ end
27
+
28
+ # Start debugger with binding.b [https://github.com/ruby/debug]
29
+ # gem "debug", ">= 1.0.0"
30
+
31
+ gem 'nokogiri', '~> 1.18', group: :development
32
+ gem 'terminal-table', '~> 3.0.2', group: :development