Class: Shadcn::CalendarComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Shadcn::CalendarComponent
- Defined in:
- app/components/shadcn/calendar_component.rb
Overview
Calendar component - date picker grid Matches shadcn/ui Calendar component
Constant Summary collapse
- CONTAINER_CLASSES =
"p-3 rounded-md border bg-background"- HEADER_CLASSES =
"flex items-center justify-between mb-4"- MONTH_YEAR_CLASSES =
"text-sm font-medium"- NAV_BUTTON_CLASSES =
"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground h-7 w-7"- WEEKDAY_CLASSES =
"text-center text-xs font-medium text-muted-foreground"- DAY_CLASSES =
"h-8 w-8 text-center text-sm p-0 relative flex items-center justify-center rounded-md cursor-pointer hover:bg-accent hover:text-accent-foreground focus:outline-none focus:ring-1 focus:ring-ring"- DAY_SELECTED_CLASSES =
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground"- DAY_TODAY_CLASSES =
"bg-accent text-accent-foreground"- DAY_OUTSIDE_CLASSES =
"text-muted-foreground opacity-50"- DAY_DISABLED_CLASSES =
"text-muted-foreground opacity-50 pointer-events-none"- WEEKDAYS =
%w[Su Mo Tu We Th Fr Sa].freeze
- WEEK_START_SYMBOLS =
Mapping for Rails beginning_of_week symbols
{ 0 => :sunday, 1 => :monday, 2 => :tuesday, 3 => :wednesday, 4 => :thursday, 5 => :friday, 6 => :saturday }.freeze
- MONTHS =
%w[January February March April May June July August September October November December].freeze
- MODES =
%i[single multiple range].freeze
Instance Attribute Summary
Attributes inherited from BaseComponent
#class_name, #data, #html_options
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(selected: nil, month: nil, min_date: nil, max_date: nil, name: nil, disabled_dates: [], disabled_days_of_week: [], show_outside_days: true, mode: :single, required: false, week_starts_on: 0, **options) ⇒ CalendarComponent
constructor
A new instance of CalendarComponent.
Methods inherited from BaseComponent
Methods included from Rails::Helpers::ClassNameHelper
Constructor Details
#initialize(selected: nil, month: nil, min_date: nil, max_date: nil, name: nil, disabled_dates: [], disabled_days_of_week: [], show_outside_days: true, mode: :single, required: false, week_starts_on: 0, **options) ⇒ CalendarComponent
Returns a new instance of CalendarComponent.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/components/shadcn/calendar_component.rb', line 54 def initialize( selected: nil, month: nil, min_date: nil, max_date: nil, name: nil, disabled_dates: [], disabled_days_of_week: [], show_outside_days: true, mode: :single, required: false, week_starts_on: 0, ** ) super(**) @selected = selected @month = month || (selected.is_a?(Array) ? selected.first : selected) || Date.today @min_date = min_date @max_date = max_date @name = name @disabled_dates = disabled_dates @disabled_days_of_week = disabled_days_of_week @show_outside_days = show_outside_days @mode = mode.to_sym @required = required @week_starts_on = week_starts_on end |
Instance Method Details
#call ⇒ Object
82 83 84 |
# File 'app/components/shadcn/calendar_component.rb', line 82 def call content_tag(:div, calendar_content, **calendar_attributes) end |