Add Alert component for DaisyUI Data Display with Button integration and Card-like parameter pattern#27
Conversation
| DEFAULT_ICONS = { | ||
| info: 'ph-info', | ||
| success: 'ph-check', | ||
| warning: 'ph-warning', | ||
| error: 'ph-x-circle' |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Removed the default icon logic completely. Icons are now only shown when explicitly passed by the user. Changes made in commit eecf52d.
| <%= 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 |
There was a problem hiding this comment.
THere should not be the need to pass icon:false
If no icon is pass not icon is shown
There was a problem hiding this comment.
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 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. |
... Fixed trailing newlines using |
| @@ -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> | |||
There was a problem hiding this comment.
Don't remove the icon from the fixture, add it to the preview.
There was a problem hiding this comment.
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> | |||
There was a problem hiding this comment.
Don't remove the icon from the fixture, add it to the preview.
There was a problem hiding this comment.
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> | |||
There was a problem hiding this comment.
Don't remove the icon from the fixture, add it to the preview.
There was a problem hiding this comment.
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 %> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
plus use <%= render DaisyUI::Alert.new ...
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
@copilot improve the previews based on the comments
| 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 |
There was a problem hiding this comment.
Converted the alert_with_title_and_description method to use an .html.erb template file as requested. Changes in commit 0445f30.
| 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 |
There was a problem hiding this comment.
Converted the alert_with_buttons_responsive method to use an .html.erb template file as requested. Changes in commit 0445f30.
| <% | ||
| 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 %> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
@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> |
There was a problem hiding this comment.
@copilot use the Button component here
There was a problem hiding this comment.
Updated the template to use DaisyUI::Button component instead of raw HTML button. Changes in commit c11f3b5.
| <div> | ||
| <button class="btn btn-sm">Deny</button> | ||
| <button class="btn btn-sm btn-primary">Accept</button> | ||
| </div> |
There was a problem hiding this comment.
@copilot use the button component here
There was a problem hiding this comment.
Updated the template to use DaisyUI::Button components instead of raw HTML buttons. Changes in commit c11f3b5.
Implemented Alert component with Card-like <%= 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 |
|
@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:
All trailing newlines fixed with |
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>
6c3cf0f to
3b9f89b
Compare
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:
info,success,warning, anderrorwith appropriate color stylingoutline,soft, anddashvariants that modify the visual appearanceactionsslot withDaisyUI::Buttoncomponentsbuttonsparameter with button configurations (Card-like pattern)verticaloptionUsage Examples
Implementation Details
DaisyUI::Alert(notDaisyUI::DataDisplay::Alert) following the engine's autoloader configurationDaisyUI::Buttoncomponents instead of raw HTML buttonsbuttonsparameter that accepts an array of button configurations, matching the Card component's button handling approachicon: falseparameters - absence of icon parameter means no icon is displayedPreviewTestConcernwith fixture-based HTML comparisonThe 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.