funicular-japan-prefectures

A Japan prefecture dropdown for Funicular, packaged as a plugin gem. Ships the JIS X 0401 code table (1..47) as data shared by the client component and server-side lookups.

Installation

# Gemfile
group :funicular do
  gem "funicular-japan-prefectures"
end

The component sources are prepended to your client bundle by funicular:compile, and funicular_plugin_include_tags serves the stylesheet.

Usage

component Funicular::Plugins::JapanPrefectures::Component,
          value: prefecture_id,          # optional preselected JIS code
          select_id: "address-prefecture",
          select_class: "border rounded px-3 py-2",
          prompt: "選択してください",
          on_change: ->(id) { @prefecture_id = id }
  • Controlled component: the parent owns value and re-renders after on_change, which receives the Integer JIS code (nil for the blank prompt option).
  • prompt — label of the blank option (default: 都道府県).
  • select_id / select_class — presentation knobs.

Server-side data

The code table has no Funicular dependency, so Rails code (mailers, PDFs, plain ERB forms) can use the same source of truth:

require "japan_prefectures/data"

Funicular::Plugins::JapanPrefectures.name_of(13)        # => "東京都"
Funicular::Plugins::JapanPrefectures.id_of("東京都")    # => 13
Funicular::Plugins::JapanPrefectures.valid_id?(48)      # => false
Funicular::Plugins::JapanPrefectures.select_options     # => [["北海道", 1], ...]

Test

bundle install && npm install
bundle exec rake test