mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
* Add notification UI * Make animation an aribtrary value It didn't make much sense in the theme as it feels very specific, this change also means the timing information is clearer within the html itself. * Update to use tailwind theme * Refactor structure of icon * Add support for multiple notifications at once * Adjust notification animation timing * Make notification more accessible Applies role to the notification which will apply the appropriate aria-live status to ensure notifications are read out when they are rendered into the screen for screenreader users. Wraps the svg with a button tag that keyboard users can focus and engage with to close the notification. * Fix notification progress indicator placement * Map flash types to notification types automatically * Refine notification animations * Set success as default icon for notifications
83 lines
3.2 KiB
Ruby
83 lines
3.2 KiB
Ruby
module ApplicationHelper
|
|
def title(page_title)
|
|
content_for(:title) { page_title }
|
|
end
|
|
|
|
def header_title(page_title)
|
|
content_for(:header_title) { page_title }
|
|
end
|
|
|
|
def permitted_accountable_partial(name)
|
|
name.underscore
|
|
end
|
|
|
|
def notification(text, **options, &block)
|
|
content = tag.p(text)
|
|
content = capture &block if block_given?
|
|
|
|
render partial: "shared/notification", locals: { type: options[:type], content: content }
|
|
end
|
|
|
|
# Wrap view with <%= modal do %> ... <% end %> to have it open in a modal
|
|
# Make sure to add data-turbo-frame="modal" to the link/button that opens the modal
|
|
def modal(&block)
|
|
content = capture &block
|
|
render partial: "shared/modal", locals: { content: content }
|
|
end
|
|
|
|
def currency_dropdown(f: nil, options: [])
|
|
render partial: "shared/currency_dropdown", locals: { f: f, options: options }
|
|
end
|
|
|
|
def sidebar_link_to(name, path, options = {})
|
|
base_class_names = [ "block", "border", "border-transparent", "rounded-xl", "-ml-2", "p-2", "text-sm", "font-medium", "text-gray-500", "flex", "items-center" ]
|
|
hover_class_names = [ "hover:bg-white", "hover:border-alpha-black-50", "hover:text-gray-900", "hover:shadow-xs" ]
|
|
current_page_class_names = [ "bg-white", "border-alpha-black-50", "text-gray-900", "shadow-xs" ]
|
|
|
|
link_class_names = if current_page?(path)
|
|
base_class_names.delete("border-transparent")
|
|
base_class_names + hover_class_names + current_page_class_names
|
|
else
|
|
base_class_names + hover_class_names
|
|
end
|
|
|
|
merged_options = options.reverse_merge(class: link_class_names.join(" ")).except(:icon)
|
|
|
|
link_to path, merged_options do
|
|
lucide_icon(options[:icon], class: "w-5 h-5 mr-2") + name
|
|
end
|
|
end
|
|
|
|
def format_currency(number, options = {})
|
|
user_currency_preference = Current.family.try(:currency) || "USD"
|
|
|
|
case user_currency_preference
|
|
when "USD"
|
|
options.reverse_merge!(unit: "$", precision: 2, delimiter: ",", separator: ".")
|
|
when "EUR"
|
|
options.reverse_merge!(unit: "€", precision: 2, delimiter: ".", separator: ",")
|
|
when "GBP"
|
|
options.reverse_merge!(unit: "£", precision: 2, delimiter: ",", separator: ".")
|
|
when "CAD"
|
|
options.reverse_merge!(unit: "C$", precision: 2, delimiter: ",", separator: ".")
|
|
when "MXN"
|
|
options.reverse_merge!(unit: "MX$", precision: 2, delimiter: ",", separator: ".")
|
|
when "HKD"
|
|
options.reverse_merge!(unit: "HK$", precision: 2, delimiter: ",", separator: ".")
|
|
when "CHF"
|
|
options.reverse_merge!(unit: "CHF", precision: 2, delimiter: ".", separator: ",")
|
|
when "SGD"
|
|
options.reverse_merge!(unit: "S$", precision: 2, delimiter: ",", separator: ".")
|
|
when "NZD"
|
|
options.reverse_merge!(unit: "NZ$", precision: 2, delimiter: ",", separator: ".")
|
|
when "AUD"
|
|
options.reverse_merge!(unit: "A$", precision: 2, delimiter: ",", separator: ".")
|
|
when "KRW"
|
|
options.reverse_merge!(unit: "₩", precision: 0, delimiter: ",", separator: ".")
|
|
else
|
|
options.reverse_merge!(unit: "$", precision: 2, delimiter: ",", separator: ".")
|
|
end
|
|
|
|
number_to_currency(number, options)
|
|
end
|
|
end
|