Skip to content

Add Alert component for DaisyUI Data Display with Button integration and Card-like parameter pattern - #27

Open
Nittarab with Copilot wants to merge 13 commits into
mainfrom
copilot/fix-26
Open

Add Alert component for DaisyUI Data Display with Button integration and Card-like parameter pattern#27
Nittarab with Copilot wants to merge 13 commits into
mainfrom
copilot/fix-26

Conversation

Copilot AI commented Aug 5, 2025

Copy link
Copy Markdown
Contributor

This PR implements a new Alert component for the DaisyUI Data Display category, providing a comprehensive solution for displaying important user notifications and messages with enhanced button integration.

Features

The Alert component supports:

  • Multiple alert types: info, success, warning, and error with appropriate color styling
  • Explicit icon control: Icons are only displayed when explicitly passed by the user - no automatic default icons
  • Variant styles: outline, soft, and dash variants that modify the visual appearance
  • Flexible content: Simple text, structured content with title/description, or custom block content
  • Enhanced button support: Two approaches for adding action buttons
    • Block syntax: Using the actions slot with DaisyUI::Button components
    • Parameter syntax: Using the buttons parameter with button configurations (Card-like pattern)
  • Responsive layout: Vertical on mobile, horizontal on larger screens with the vertical option

Usage Examples

<!-- Basic alert without any icon -->
<%= render DaisyUI::Alert.new(text: "12 unread messages. Tap to see.") %>

<!-- Success alert without icon -->
<%= render DaisyUI::Alert.new(text: "Your purchase has been confirmed!", color: :success) %>

<!-- Alert with explicit icon -->
<%= render DaisyUI::Alert.new(
  text: "New message!", 
  color: :info, 
  icon: helpers.info_icon
) %>

<!-- Card-like button parameter pattern -->
<%= render DaisyUI::Alert.new(
  text: "Accept cookies?",
  vertical: true,
  buttons: [
    { text: "Deny", size: :sm },
    { text: "Accept", size: :sm, color: :primary }
  ]
) %>

<!-- Block syntax with Button components -->
<%
  alert = DaisyUI::Alert.new(text: "Important message", vertical: true)
  alert.with_actions do
    render DaisyUI::Button.new(text: "Dismiss", size: :sm)
  end
  render alert
%>

Implementation Details

  • Namespace collapsing: Component class is DaisyUI::Alert (not DaisyUI::DataDisplay::Alert) following the engine's autoloader configuration
  • Alert::Actions subcomponent: Created similar to Card::Actions for handling button layouts and configurations
  • Button integration: All templates use DaisyUI::Button components instead of raw HTML buttons
  • Card-like pattern: Supports buttons parameter that accepts an array of button configurations, matching the Card component's button handling approach
  • Icon philosophy: No automatic icon assignment - users must explicitly pass icons when desired
  • Clean API: No need for icon: false parameters - absence of icon parameter means no icon is displayed
  • Backward compatibility: All existing functionality preserved while adding new button parameter support
  • Testing: Comprehensive test coverage using PreviewTestConcern with fixture-based HTML comparison

The component follows all established patterns in the codebase and produces clean, predictable HTML output.

Fixes #26.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add new Alert component Add Alert component for DaisyUI Data Display Aug 5, 2025
Copilot AI requested a review from Nittarab August 5, 2025 14:18
Comment on lines +49 to +53
DEFAULT_ICONS = {
info: 'ph-info',
success: 'ph-check',
warning: 'ph-warning',
error: 'ph-x-circle'

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PJ for the icon, I'm not part of this component library, so the default icon should not be set.

The user should pass the icon. always

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the default icon logic completely. Icons are now only shown when explicitly passed by the user. Changes made in commit eecf52d.

Comment on lines +1 to +4
<%= render DaisyUI::Alert.new(text: '12 unread messages. Tap to see.', color: :info, variant: :dash, icon: false) %>
<%= render DaisyUI::Alert.new(text: 'Your purchase has been confirmed!', color: :success, variant: :dash, icon: false) %>
<%= render DaisyUI::Alert.new(text: 'Warning: Invalid email address!', color: :warning, variant: :dash, icon: false) %>
<%= render DaisyUI::Alert.new(text: 'Error! Task failed successfully.', color: :error, variant: :dash, icon: false) %> No newline at end of file

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THere should not be the need to pass icon:false
If no icon is pass not icon is shown

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the need for icon: false parameter. If no icon is passed, no icon is shown automatically. Updated all template files in commit eecf52d.

Copilot AI changed the title Add Alert component for DaisyUI Data Display Add Alert component for DaisyUI Data Display with explicit icon control Aug 5, 2025
Copilot AI requested a review from Nittarab August 5, 2025 14:47
@Nittarab
Nittarab marked this pull request as ready for review August 5, 2025 14:48
@Nittarab

Nittarab commented Aug 5, 2025

Copy link
Copy Markdown
Owner

@copilot
Use the bin/fix_trailing_newlines.sh to fix the lint offences and

Please find a solution for failing job 47429748286. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Copilot AI commented Aug 5, 2025

Copy link
Copy Markdown
Contributor Author

@copilot
Use the bin/fix_trailing_newlines.sh to fix the lint offences and

...

Fixed trailing newlines using bin/fix_trailing_newlines.sh and resolved the failing job by updating test fixtures to match the no-default-icon behavior. The tests were failing because fixtures expected default icons that are no longer rendered automatically. Changes made in commit 3a4ffd5.

@@ -1,5 +1,4 @@
<div role="alert" class="alert alert-vertical sm:alert-horizontal">
<i class="ph ph-info h-6 w-6 shrink-0"></i>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove the icon from the fixture, add it to the preview.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by restoring the original fixture with the icon and updating the alert_with_buttons_responsive preview method to explicitly pass info_icon. Also converted from template-based to direct component usage as suggested. Changes in commit cdd548f.

@@ -1,4 +1,3 @@
<div role="alert" class="alert alert-error">
<i class="ph ph-x-circle h-6 w-6 shrink-0"></i>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove the icon from the fixture, add it to the preview.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by restoring the original fixture with the icon and updating the error_color preview method to explicitly pass error_icon. Changes in commit cdd548f.

@@ -1,4 +1,3 @@
<div role="alert" class="alert alert-success">
<i class="ph ph-check h-6 w-6 shrink-0"></i>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove the icon from the fixture, add it to the preview.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by restoring the original fixture with the icon and updating the success_color preview method to explicitly pass check_icon. Changes in commit cdd548f.

text: 'we use cookies for no reason.',
vertical: true
) %>
<% alert.with_actions do %>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, we should be able to use the bottom component and pass all the attributes of the bottom component, as it has been done in the cart component, to the alert.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plus use <%= render DaisyUI::Alert.new ...

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot check the commets

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converted the alert_with_buttons_responsive method to build the component directly instead of using a template, following the pattern used in other components like Accordion. The component is now built with all attributes passed directly to DaisyUI::Alert.new() and uses with_actions for the buttons. Changes in commit cdd548f.

@Nittarab Nittarab left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot improve the previews based on the comments

Comment on lines +83 to +92
alert = DaisyUI::Alert.new(
color: :info,
title: 'New message!',
description: 'You have 1 unread message',
vertical: true
)
alert.with_actions do
tag.button('See', class: 'btn btn-sm')
end
render alert

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert this to .html.erb

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converted the alert_with_title_and_description method to use an .html.erb template file as requested. Changes in commit 0445f30.

Comment on lines +96 to +107
alert = DaisyUI::Alert.new(
text: 'we use cookies for no reason.',
vertical: true,
icon: info_icon
)
alert.with_actions do
tag.div do
tag.button('Deny', class: 'btn btn-sm') +
tag.button('Accept', class: 'btn btn-sm btn-primary')
end
end
render alert

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert this to .html.erb

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converted the alert_with_buttons_responsive method to use an .html.erb template file as requested. Changes in commit 0445f30.

@Nittarab Nittarab left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

Comment on lines +1 to +12
<%
alert = DaisyUI::Alert.new(
color: :info,
title: 'New message!',
description: 'You have 1 unread message',
vertical: true
)
alert.with_actions do
tag.button('See', class: 'btn btn-sm')
end
%>
<%= render alert %>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way of rendering the component is not actually aligned with the other way of doing the preview. We can render and directly define the component. No need to define it first and then render it.

Same for all the previews

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated both Alert preview templates to use direct rendering with block syntax instead of creating component variables first. The templates now follow the established pattern used by other components in the codebase. Changes in commit 1dc9fad.

@Nittarab Nittarab left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I honestly really like how the car component is implemented:
DaisyUI::Card.new(
title: 'Card Title',
description: 'A card component has a figure, a body part, and inside body there are title and actions parts',
button: { text: 'Buy Now', color: :primary, justify: :end },
variant: :bordered,
class: 'w-96'
)

As you see here, we can pass the button: params with all the args

check the impleentation inside the https://github.com/Nittarab/daisy_components/blob/main/app/components/daisy_ui/data_display/card/actions.rb actions subcomponet.

Maybe we can have a similar implementation for the alert?

vertical: true
) do |component| %>
<% component.with_actions do %>
<button class="btn btn-sm">See</button>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot use the Button component here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the template to use DaisyUI::Button component instead of raw HTML button. Changes in commit c11f3b5.

Comment on lines +7 to +10
<div>
<button class="btn btn-sm">Deny</button>
<button class="btn btn-sm btn-primary">Accept</button>
</div>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot use the button component here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the template to use DaisyUI::Button components instead of raw HTML buttons. Changes in commit c11f3b5.

Copilot AI commented Aug 6, 2025

Copy link
Copy Markdown
Contributor Author

@copilot I honestly really like how the car component is implemented:
DaisyUI::Card.new(
title: 'Card Title',...

Implemented Alert component with Card-like buttons parameter pattern! You can now pass button configurations directly:

<%= render DaisyUI::Alert.new(
  text: 'Accept cookies?',
  buttons: [
    { text: 'Deny', size: :sm },
    { text: 'Accept', size: :sm, color: :primary }
  ]
) %>

Added Alert::Actions subcomponent similar to Card::Actions, and updated all templates to use DaisyUI::Button components. Changes in commit c11f3b5.

Copilot AI changed the title Add Alert component for DaisyUI Data Display with explicit icon control Add Alert component for DaisyUI Data Display with Button integration and Card-like parameter pattern Aug 6, 2025
Copilot AI requested a review from Nittarab August 6, 2025 14:07
@Nittarab

Nittarab commented Aug 7, 2025

Copy link
Copy Markdown
Owner

@copilot make sure that the tests are not failing and Robocop offenses are not failing. Run the script to fit the last line of the file.

Copilot AI commented Aug 7, 2025

Copy link
Copy Markdown
Contributor Author

@copilot make sure that the tests are not failing and Robocop offenses are not failing. Run the script to fit the last line of the file.

Fixed trailing newlines and test failures. The issues were:

  1. Missing icon classes: Added h-6 w-6 shrink-0 classes to icon calls in preview methods
  2. Extra div wrapper: Removed redundant div wrapper in alert_with_buttons_responsive template
  3. Missing icon: Added icon to alert_with_title_and_description template
  4. Fixture mismatch: Updated fixture to include missing icon

All trailing newlines fixed with bin/fix_trailing_newlines.sh. Changes in commit 6c3cf0f.

Copilot AI and others added 13 commits August 10, 2025 12:33
Co-authored-by: Nittarab <6181406+Nittarab@users.noreply.github.com>
Co-authored-by: Nittarab <6181406+Nittarab@users.noreply.github.com>
Co-authored-by: Nittarab <6181406+Nittarab@users.noreply.github.com>
…havior

Co-authored-by: Nittarab <6181406+Nittarab@users.noreply.github.com>
Co-authored-by: Nittarab <6181406+Nittarab@users.noreply.github.com>
Co-authored-by: Nittarab <6181406+Nittarab@users.noreply.github.com>
Co-authored-by: Nittarab <6181406+Nittarab@users.noreply.github.com>
Co-authored-by: Nittarab <6181406+Nittarab@users.noreply.github.com>
…parameter fixture

Co-authored-by: Nittarab <6181406+Nittarab@users.noreply.github.com>
…iv wrapper

Co-authored-by: Nittarab <6181406+Nittarab@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add new Alert component

2 participants