@spree/docs 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/api-reference/store-api/errors.md +2 -2
  2. package/dist/api-reference/store-api/idempotency.md +1 -1
  3. package/dist/api-reference/store-api/localization.md +4 -4
  4. package/dist/api-reference/store-api/metadata.md +2 -2
  5. package/dist/api-reference/store.yaml +10599 -0
  6. package/dist/api-reference/storefront/authentication.md +2 -2
  7. package/dist/api-reference/tutorials/adyen-integration-guide-for-android.md +2 -2
  8. package/dist/api-reference/tutorials/adyen-integration-guide-for-ios.md +2 -2
  9. package/dist/api-reference/tutorials/quick-checkout-with-stripe.md +8 -8
  10. package/dist/api-reference/v2/introduction.md +2 -2
  11. package/dist/api-reference/webhooks-events.md +2 -2
  12. package/dist/developer/admin/admin.md +18 -18
  13. package/dist/developer/admin/components.md +1 -1
  14. package/dist/developer/admin/extending-ui.md +26 -26
  15. package/dist/developer/admin/helper-methods.md +2 -2
  16. package/dist/developer/admin/navigation.md +5 -5
  17. package/dist/developer/admin/tables.md +4 -4
  18. package/dist/developer/cli/quickstart.md +2 -2
  19. package/dist/developer/contributing/creating-an-extension.md +12 -12
  20. package/dist/developer/contributing/quickstart.md +1 -1
  21. package/dist/developer/core-concepts/addresses.md +11 -11
  22. package/dist/developer/core-concepts/adjustments.md +8 -8
  23. package/dist/developer/core-concepts/architecture.md +21 -21
  24. package/dist/developer/core-concepts/calculators.md +4 -4
  25. package/dist/developer/core-concepts/customers.md +9 -9
  26. package/dist/developer/core-concepts/events.md +5 -5
  27. package/dist/developer/core-concepts/inventory.md +5 -5
  28. package/dist/developer/core-concepts/markets.md +10 -10
  29. package/dist/developer/core-concepts/media.md +3 -3
  30. package/dist/developer/core-concepts/metafields.md +6 -6
  31. package/dist/developer/core-concepts/orders.md +14 -14
  32. package/dist/developer/core-concepts/payments.md +9 -9
  33. package/dist/developer/core-concepts/pricing.md +10 -10
  34. package/dist/developer/core-concepts/products.md +10 -10
  35. package/dist/developer/core-concepts/promotions.md +5 -5
  36. package/dist/developer/core-concepts/reports.md +2 -2
  37. package/dist/developer/core-concepts/search-filtering.md +7 -7
  38. package/dist/developer/core-concepts/shipments.md +13 -13
  39. package/dist/developer/core-concepts/slugs.md +3 -3
  40. package/dist/developer/core-concepts/staff-roles.md +7 -7
  41. package/dist/developer/core-concepts/store-credits-gift-cards.md +4 -4
  42. package/dist/developer/core-concepts/stores.md +15 -15
  43. package/dist/developer/core-concepts/taxes.md +11 -11
  44. package/dist/developer/core-concepts/translations.md +6 -6
  45. package/dist/developer/core-concepts/users.md +12 -12
  46. package/dist/developer/core-concepts/webhooks.md +8 -8
  47. package/dist/developer/create-spree-app/quickstart.md +5 -5
  48. package/dist/developer/customization/api.md +2 -2
  49. package/dist/developer/customization/authentication.md +2 -2
  50. package/dist/developer/customization/checkout.md +7 -7
  51. package/dist/developer/customization/decorators.md +24 -24
  52. package/dist/developer/customization/dependencies.md +1 -1
  53. package/dist/developer/customization/metadata.md +3 -3
  54. package/dist/developer/customization/permissions.md +1 -1
  55. package/dist/developer/customization/quickstart.md +9 -9
  56. package/dist/developer/customization/v4/checkout.md +3 -3
  57. package/dist/developer/customization/v4/deface.md +1 -1
  58. package/dist/developer/deployment/assets.md +1 -1
  59. package/dist/developer/deployment/aws.md +5 -5
  60. package/dist/developer/deployment/docker.md +2 -2
  61. package/dist/developer/deployment/environment_variables.md +1 -1
  62. package/dist/developer/deployment/render.md +5 -5
  63. package/dist/developer/getting-started/quickstart.md +2 -2
  64. package/dist/developer/how-to/custom-payment-method.md +6 -6
  65. package/dist/developer/how-to/custom-promotion.md +7 -7
  66. package/dist/developer/how-to/custom-report.md +3 -3
  67. package/dist/developer/how-to/custom-search-provider.md +7 -7
  68. package/dist/developer/multi-store/quickstart.md +1 -1
  69. package/dist/developer/multi-tenant/quickstart.md +1 -1
  70. package/dist/developer/sdk/authentication.md +1 -1
  71. package/dist/developer/sdk/configuration.md +1 -1
  72. package/dist/developer/sdk/store/markets.md +3 -3
  73. package/dist/developer/storefront/nextjs/customization.md +1 -1
  74. package/dist/developer/storefront/nextjs/quickstart.md +2 -2
  75. package/dist/developer/tutorial/admin.md +2 -2
  76. package/dist/developer/tutorial/extending-models.md +15 -15
  77. package/dist/developer/tutorial/file-uploads.md +1 -1
  78. package/dist/developer/tutorial/introduction.md +7 -7
  79. package/dist/developer/tutorial/rich-text.md +1 -1
  80. package/dist/developer/tutorial/testing.md +5 -61
  81. package/dist/developer/upgrades/3.7-to-4.0.md +1 -1
  82. package/dist/developer/upgrades/4.0-to-4.1.md +1 -1
  83. package/dist/developer/upgrades/4.10-to-5.0.md +1 -1
  84. package/dist/developer/upgrades/4.5-to-4.6.md +4 -4
  85. package/dist/developer/upgrades/4.8-to-4.9.md +1 -1
  86. package/dist/developer/upgrades/4.9-to-4.10.md +1 -1
  87. package/dist/developer/upgrades/5.0-to-5.1.md +1 -1
  88. package/dist/developer/upgrades/5.1-to-5.2.md +2 -2
  89. package/dist/developer/upgrades/5.2-to-5.3.md +2 -2
  90. package/dist/developer/upgrades/5.3-to-5.4.md +5 -5
  91. package/dist/developer/upgrades/quickstart.md +1 -1
  92. package/dist/integrations/integrations.md +10 -10
  93. package/dist/integrations/payments/adyen.md +1 -1
  94. package/dist/integrations/search/meilisearch.md +2 -2
  95. package/package.json +7 -2
  96. package/dist/developer/storefront/blocks.md +0 -285
  97. package/dist/developer/storefront/custom-css.md +0 -260
  98. package/dist/developer/storefront/custom-javascript.md +0 -166
  99. package/dist/developer/storefront/helper-methods.md +0 -1288
  100. package/dist/developer/storefront/links.md +0 -298
  101. package/dist/developer/storefront/pages.md +0 -163
  102. package/dist/developer/storefront/sections.md +0 -569
  103. package/dist/developer/storefront/storefront.md +0 -56
  104. package/dist/developer/storefront/themes.md +0 -161
  105. package/dist/developer/tutorial/page-builder.md +0 -487
  106. package/dist/developer/tutorial/seo.md +0 -332
  107. package/dist/developer/tutorial/storefront.md +0 -352
@@ -1,285 +0,0 @@
1
- ---
2
- title: "Blocks"
3
- description: "Learn how to utilize blocks to build your Spree Storefront"
4
- ---
5
-
6
- Blocks are the lowest level of components in Spree Storefront. They are nested inside [sections](/developer/storefront/sections) and represent individual content elements like headings, text, buttons, and images.
7
-
8
- ## How Blocks Work
9
-
10
- Each section can contain multiple blocks that store staff can manage through the Page Builder:
11
-
12
- - Add new blocks
13
- - Edit block content and settings
14
- - Reorder blocks via drag-and-drop
15
- - Remove blocks
16
-
17
- Not all sections support blocks. A section must explicitly enable block support by implementing `blocks_available?` and `available_blocks_to_add` methods.
18
-
19
- ## Built-in Block Types
20
-
21
- Spree comes with several built-in block types:
22
-
23
- ### Content Blocks
24
-
25
- | Block | Description | Class |
26
- |-------|-------------|-------|
27
- | Heading | Large text headings | [Spree::PageBlocks::Heading](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/heading.rb) |
28
- | Subheading | Smaller secondary headings | [Spree::PageBlocks::Subheading](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/subheading.rb) |
29
- | Text | Rich text content | [Spree::PageBlocks::Text](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/text.rb) |
30
- | Buttons | Call-to-action buttons with links | [Spree::PageBlocks::Buttons](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/buttons.rb) |
31
- | Image | Image with optional link | [Spree::PageBlocks::Image](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/image.rb) |
32
-
33
- ### Navigation Blocks
34
-
35
- | Block | Description | Class |
36
- |-------|-------------|-------|
37
- | Nav | Simple navigation links | [Spree::PageBlocks::Nav](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/nav.rb) |
38
- | Mega Nav | Mega menu navigation | [Spree::PageBlocks::MegaNav](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/mega_nav.rb) |
39
- | Link | Single link item | [Spree::PageBlocks::Link](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/link.rb) |
40
-
41
- ### Product Blocks
42
-
43
- These blocks are used in the Product Details section:
44
-
45
- | Block | Description | Class |
46
- |-------|-------------|-------|
47
- | Title | Product title | [Spree::PageBlocks::Products::Title](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/products/title.rb) |
48
- | Price | Product price display | [Spree::PageBlocks::Products::Price](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/products/price.rb) |
49
- | Description | Product description | [Spree::PageBlocks::Products::Description](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/products/description.rb) |
50
- | Variant Picker | Size/color selector | [Spree::PageBlocks::Products::VariantPicker](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/products/variant_picker.rb) |
51
- | Quantity Selector | Quantity input | [Spree::PageBlocks::Products::QuantitySelector](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/products/quantity_selector.rb) |
52
- | Buy Buttons | Add to cart button | [Spree::PageBlocks::Products::BuyButtons](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/products/buy_buttons.rb) |
53
- | Share | Social sharing buttons | [Spree::PageBlocks::Products::Share](https://github.com/spree/spree/blob/main/core/app/models/spree/page_blocks/products/share.rb) |
54
-
55
- ## Architecture
56
-
57
- ### Base Class
58
-
59
- All blocks inherit from [Spree::PageBlock](https://github.com/spree/spree/blob/main/core/app/models/spree/page_block.rb):
60
-
61
- ```ruby
62
- module Spree
63
- class PageBlock < Spree.base_class
64
- include Spree::HasPageLinks
65
-
66
- belongs_to :section, class_name: 'Spree::PageSection'
67
-
68
- has_rich_text :text
69
- has_one_attached :asset
70
-
71
- # Default preferences
72
- preference :text_alignment, :string, default: 'left'
73
- preference :container_alignment, :string, default: 'left'
74
- preference :size, :string, default: 'medium'
75
- preference :width_desktop, :integer, default: 100
76
- preference :top_padding, :integer, default: 0
77
- preference :bottom_padding, :integer, default: 0
78
- end
79
- end
80
- ```
81
-
82
- ### Default Preferences
83
-
84
- Every block has these default preferences:
85
-
86
- | Preference | Type | Default | Description |
87
- |------------|------|---------|-------------|
88
- | `text_alignment` | String | `left` | Text alignment (left, center, right) |
89
- | `container_alignment` | String | `left` | Container alignment |
90
- | `size` | String | `medium` | Block size (small, medium, large) |
91
- | `width_desktop` | Integer | `100` | Width percentage on desktop |
92
- | `top_padding` | Integer | `0` | Top padding in pixels |
93
- | `bottom_padding` | Integer | `0` | Bottom padding in pixels |
94
-
95
- ### Associations
96
-
97
- - **Section**: Each block belongs to a section (`section`)
98
- - **Links**: Blocks can have multiple links (`links`) via `Spree::HasPageLinks`
99
- - **Asset**: Blocks can have an attached image (`asset`)
100
- - **Rich Text**: Blocks can have rich text content (`text`)
101
-
102
- ## Accessing Blocks
103
-
104
- ```ruby
105
- # Get all blocks for a section
106
- section.blocks
107
-
108
- # Get blocks with eager loading
109
- section.blocks.includes(:rich_text_text, :links)
110
-
111
- # Find specific block type
112
- section.blocks.where(type: 'Spree::PageBlocks::Heading')
113
- ```
114
-
115
- ## Rendering Blocks
116
-
117
- In storefront section views, blocks are rendered within their parent section:
118
-
119
- ```erb
120
- <% section.blocks.each do |block| %>
121
- <% case block.type %>
122
- <% when 'Spree::PageBlocks::Heading' %>
123
- <h2 <%= block_attributes(block) %>>
124
- <%= block.text %>
125
- </h2>
126
- <% when 'Spree::PageBlocks::Text' %>
127
- <div <%= block_attributes(block) %>>
128
- <%= block.text %>
129
- </div>
130
- <% when 'Spree::PageBlocks::Buttons' %>
131
- <div <%= block_attributes(block) %>>
132
- <% if block.link %>
133
- <%= page_builder_link_to block.link, class: 'btn-primary' %>
134
- <% end %>
135
- </div>
136
- <% end %>
137
- <% end %>
138
- ```
139
-
140
- The `block_attributes(block)` helper returns data attributes needed for Page Builder editing.
141
-
142
- ## Creating a Custom Block
143
-
144
- ### Step 1: Create the Model
145
-
146
- ```ruby app/models/spree/page_blocks/quote.rb
147
- module Spree
148
- module PageBlocks
149
- class Quote < Spree::PageBlock
150
- SIZE_DEFAULT = 'large'
151
- TEXT_ALIGNMENT_DEFAULT = 'center'
152
-
153
- preference :author_name, :string
154
- preference :author_title, :string
155
- preference :text_color, :string
156
- preference :background_color, :string
157
-
158
- def icon_name
159
- 'quote'
160
- end
161
-
162
- def display_name
163
- text.to_plain_text.truncate(30)
164
- end
165
- end
166
- end
167
- end
168
- ```
169
-
170
- ### Step 2: Register the Block
171
-
172
- ```ruby config/initializers/spree.rb
173
- Rails.application.config.after_initialize do
174
- Spree.page_builder.page_blocks += [
175
- Spree::PageBlocks::Quote
176
- ]
177
- end
178
- ```
179
-
180
- ### Step 3: Add to Section's Available Blocks
181
-
182
- In your section model, add the new block type:
183
-
184
- ```ruby
185
- def available_blocks_to_add
186
- [
187
- Spree::PageBlocks::Heading,
188
- Spree::PageBlocks::Text,
189
- Spree::PageBlocks::Quote # Your new block
190
- ]
191
- end
192
- ```
193
-
194
- ### Step 4: Create Admin Form
195
-
196
- ```erb app/views/spree/admin/page_blocks/forms/_quote.html.erb
197
- <div class="form-group">
198
- <%= f.label :text, Spree.t(:quote_text) %>
199
- <%= f.rich_text_area :text, data: { action: 'auto-submit#submit' } %>
200
- </div>
201
-
202
- <div class="form-group">
203
- <%= f.label :preferred_author_name, Spree.t(:author_name) %>
204
- <%= f.text_field :preferred_author_name,
205
- class: 'form-control',
206
- data: { action: 'auto-submit#submit' } %>
207
- </div>
208
-
209
- <div class="form-group">
210
- <%= f.label :preferred_author_title, Spree.t(:author_title) %>
211
- <%= f.text_field :preferred_author_title,
212
- class: 'form-control',
213
- data: { action: 'auto-submit#submit' } %>
214
- </div>
215
- ```
216
-
217
- ### Step 5: Render in Section View
218
-
219
- Add rendering logic to your section's storefront view:
220
-
221
- ```erb
222
- <% when 'Spree::PageBlocks::Quote' %>
223
- <blockquote <%= block_attributes(block) %> class="text-<%= block.preferred_text_alignment %>">
224
- <p class="text-xl italic"><%= block.text %></p>
225
- <% if block.preferred_author_name.present? %>
226
- <footer class="mt-4">
227
- <cite>
228
- <strong><%= block.preferred_author_name %></strong>
229
- <% if block.preferred_author_title.present? %>
230
- <br><span class="text-sm text-gray-500"><%= block.preferred_author_title %></span>
231
- <% end %>
232
- </cite>
233
- </footer>
234
- <% end %>
235
- </blockquote>
236
- ```
237
-
238
- ## Block with Links
239
-
240
- To add link support to your block, include the `Spree::HasOneLink` concern:
241
-
242
- ```ruby
243
- module Spree
244
- module PageBlocks
245
- class CallToAction < Spree::PageBlock
246
- include Spree::HasOneLink
247
-
248
- preference :button_style, :string, default: 'primary'
249
-
250
- # Called when the link is destroyed
251
- def link_destroyed(_link)
252
- destroy if page_links_count.zero?
253
- end
254
- end
255
- end
256
- end
257
- ```
258
-
259
- ## Block with Image
260
-
261
- Blocks automatically have an `asset` attachment available:
262
-
263
- ```ruby
264
- # Check if image is attached
265
- block.asset.attached?
266
-
267
- # Display image in view
268
- <% if block.asset.attached? %>
269
- <%= spree_image_tag block.asset, width: 400, height: 300 %>
270
- <% end %>
271
- ```
272
-
273
- ## Key Methods
274
-
275
- | Method | Description |
276
- |--------|-------------|
277
- | `display_name` | Name shown in Page Builder sidebar |
278
- | `icon_name` | Icon from [Tabler Icons](https://tabler.io/icons) |
279
- | `form_partial_name` | Name of the admin form partial |
280
-
281
- ## Related Documentation
282
-
283
- - [Sections](/developer/storefront/sections) - Parent containers for blocks
284
- - [Links](/developer/storefront/links) - Adding links to blocks
285
- - [Media](/developer/core-concepts/media) - Working with images
@@ -1,260 +0,0 @@
1
- ---
2
- title: "Custom CSS for Spree Storefront"
3
- sidebarTitle: "Custom CSS"
4
- description: "Learn how to add custom CSS stylesheets to your Spree storefront"
5
- ---
6
-
7
- Spree Storefront is built on top of [Tailwind CSS 4](https://tailwindcss.com/). After installing Spree you should find a main CSS file:
8
-
9
- * [app/assets/tailwind/application.css](https://github.com/spree/spree/blob/main/storefront/lib/generators/spree/storefront/install/templates/application.css) - This is the main CSS file that imports Tailwind and adds storefront styles
10
-
11
- If you're missing this file, or migrating from a previous version of Spree, you can generate it using the following command:
12
-
13
- ```bash
14
- bin/rails g spree:storefront:install
15
- ```
16
-
17
- > **INFO:** Tailwind 4 uses a CSS-first configuration approach. There's no `tailwind.config.js` file - all configuration is done directly in CSS using the `@theme` directive.
18
-
19
- ## Basic Structure
20
-
21
- Your [application.css](https://github.com/spree/spree/blob/main/storefront/lib/generators/spree/storefront/install/templates/application.css) file should look something like this:
22
-
23
- ```css app/assets/tailwind/application.css
24
- @import "tailwindcss";
25
-
26
- @theme {
27
- /* Theme customizations go here */
28
- }
29
-
30
- /* Your custom styles */
31
- ```
32
-
33
- ## Importing Additional CSS Files
34
-
35
- Create a new CSS file in the `app/assets/stylesheets` directory:
36
-
37
- ```bash
38
- touch app/assets/tailwind/my_custom_styles.css
39
- ```
40
-
41
- In the `my_custom_styles.css` file, add your styles:
42
-
43
- ```css
44
- .my-custom-class {
45
- color: red;
46
- }
47
- ```
48
-
49
- Then import it in your `application.css` file:
50
-
51
- ```css app/assets/tailwind/application.css
52
- @import "tailwindcss";
53
- @import "my_custom_styles.css"; /* [!code ++] */
54
- ```
55
-
56
- ## Importing 3rd Party CSS Libraries
57
-
58
- You can import a 3rd party CSS library directly from a CDN:
59
-
60
- ```css app/assets/tailwind/application.css
61
- @import "tailwindcss";
62
- @import url("https://esm.sh/swiper@11.2.2/swiper-bundle.min.css"); /* [!code ++] */
63
- ```
64
-
65
- ## CSS Variables
66
-
67
- Spree Storefront uses CSS variables that are automatically injected into the page. This allows store owners to change colors, fonts, etc. from the admin dashboard via Page Builder.
68
-
69
- The default variables look like this:
70
-
71
- ```css app/assets/tailwind/application.css
72
- :root {
73
- --primary: #000000;
74
- --accent: #F0EFE9;
75
- --danger: #C73528;
76
- --success: #00C773;
77
- --neutral: #999999;
78
-
79
- --background: #FFFFFF;
80
- --text: #000000;
81
-
82
- --border-default-color: #E9E7DC;
83
- --border-default-width: 1px;
84
- --border-default-radius: 6px;
85
-
86
- --button: #000000;
87
- --button-rgb: 0, 0, 0;
88
- --button-text: #ffffff;
89
- --button-border-radius: 100px;
90
- --button-border-width: 1px;
91
- --button-border-color: ;
92
-
93
- --button-hover: #000000;
94
- --button-hover-text: #ffffff;
95
-
96
- --secondary-button: #FFFFFF;
97
- --secondary-button-text: #000000;
98
- --secondary-button-hover: #000000;
99
- --secondary-button-hover-text: #FFFFFF;
100
-
101
- --input: #E9E7DC;
102
- --input-bg: #ffffff;
103
- --input-text: #6b7280;
104
- --input-focus-bg: #ffffff;
105
- --input-border-radius: 8px;
106
-
107
- --neutral-50: #F3F3F3;
108
- --neutral-100: #EAEAEA;
109
- --neutral-200: #D4D4D4;
110
- --neutral-300: #B3B3B3;
111
- --neutral-400: #999999;
112
- --neutral-500: #808080;
113
- --neutral-600: #666666;
114
- --neutral-700: #4D4D4D;
115
- --neutral-800: #333333;
116
- --neutral-900: #1A1A1A;
117
- --accent-100: #FBFAF8;
118
- }
119
- ```
120
-
121
- They are defined in the [app/views/themes/default/spree/shared/_css_variables.html.erb](https://github.com/spree/spree/blob/main/storefront/app/views/themes/default/spree/shared/_css_variables.html.erb) file which should be present in your theme.
122
-
123
- ## Customizing with @theme
124
-
125
- Tailwind 4 uses the `@theme` directive for customizations. You can extend or override the default theme:
126
-
127
- ```css app/assets/tailwind/application.css
128
- @import "tailwindcss";
129
-
130
- @theme {
131
- /* Add custom colors using Spree's CSS variables */
132
- --color-primary: var(--primary);
133
- --color-accent: var(--accent);
134
- --color-danger: var(--danger);
135
- --color-success: var(--success);
136
-
137
- /* Add custom fonts */
138
- --font-display: "Playfair Display", serif;
139
-
140
- /* Add custom spacing */
141
- --spacing-18: 4.5rem;
142
-
143
- /* Add custom border radius */
144
- --radius-button: var(--button-border-radius);
145
- }
146
- ```
147
-
148
- Then use them in your templates:
149
-
150
- ```erb
151
- <div class="bg-primary text-white font-display p-18 rounded-button">
152
- Custom styled content
153
- </div>
154
- ```
155
-
156
- ## Overriding Section Styles
157
-
158
- Each section has CSS classes you can target to customize its appearance:
159
-
160
- ```css
161
- /* Section container classes follow the pattern: section-{section-type} */
162
- .section-image-with-text {
163
- /* Custom styles for Image with Text section */
164
- }
165
-
166
- .section-featured-taxon {
167
- /* Custom styles for Featured Taxon section */
168
- }
169
-
170
- /* Block-specific styles within sections */
171
- .image-with-text--heading {
172
- font-family: serif;
173
- }
174
-
175
- .rich-text--text {
176
- line-height: 1.8;
177
- }
178
- ```
179
-
180
- ## Using Tailwind Utility Classes
181
-
182
- You can use Tailwind utility classes directly in your templates:
183
-
184
- ```erb
185
- <div class="flex items-center gap-4 p-6 bg-accent rounded-lg">
186
- <%= product.name %>
187
- </div>
188
- ```
189
-
190
- ### Arbitrary Values
191
-
192
- Tailwind 4 supports arbitrary values for one-off customizations:
193
-
194
- ```erb
195
- <div class="p-[17px] bg-[#1a1a1a] text-[13px] grid-cols-[1fr_2fr]">
196
- Custom values
197
- </div>
198
- ```
199
-
200
- ### Variant Modifiers
201
-
202
- Use variant modifiers for responsive and state-based styles:
203
-
204
- ```erb
205
- <div class="p-4 md:p-6 lg:p-8 hover:bg-accent active:scale-95">
206
- Responsive and interactive
207
- </div>
208
- ```
209
-
210
- ## Adding Custom Utilities
211
-
212
- You can add custom utilities using standard CSS with the `@utility` directive:
213
-
214
- ```css
215
- @import "tailwindcss";
216
-
217
- @utility content-auto {
218
- content-visibility: auto;
219
- }
220
-
221
- @utility scrollbar-hidden {
222
- scrollbar-width: none;
223
- &::-webkit-scrollbar {
224
- display: none;
225
- }
226
- }
227
- ```
228
-
229
- Then use them like any other utility:
230
-
231
- ```erb
232
- <div class="content-auto scrollbar-hidden">
233
- <!-- Content -->
234
- </div>
235
- ```
236
-
237
- ## Adding Custom Variants
238
-
239
- Create custom variants with the `@variant` directive:
240
-
241
- ```css
242
- @import "tailwindcss";
243
-
244
- @variant pointer-coarse (@media (pointer: coarse));
245
- @variant theme-dark (&:where([data-theme="dark"], [data-theme="dark"] *));
246
- ```
247
-
248
- Use them in your templates:
249
-
250
- ```erb
251
- <button class="p-2 pointer-coarse:p-4 theme-dark:bg-gray-800">
252
- Touch-friendly button
253
- </button>
254
- ```
255
-
256
- ## Related Documentation
257
-
258
- - [Themes](/developer/storefront/themes) - Theme settings and colors
259
- - [Custom JavaScript](/developer/storefront/custom-javascript) - Adding interactivity
260
- - [Tailwind CSS 4 Documentation](https://tailwindcss.com/docs) - Official Tailwind docs
@@ -1,166 +0,0 @@
1
- ---
2
- title: "Custom JavaScript for Spree Storefront"
3
- sidebarTitle: "Custom JavaScript"
4
- description: "Learn how to add custom JavaScript to your Spree storefront"
5
- ---
6
-
7
- ## Extending Storefront with JavaScript
8
-
9
- Spree Storefront can be easily extended with custom JavaScript. Most of the JavaScript in the storefront is powered by a framework called [Stimulus.js](https://stimulus.hotwired.dev/) which is the Ruby on Rails default. It's a very simple and minimalistic framework only enhancing our server-side rendered HTML with a bit of interactivity.
10
-
11
- ### 3rd party JavaScript libraries
12
-
13
- Spree Storefront comes with a few 3rd party JavaScript libraries already included.
14
-
15
- Main libraries we're using:
16
-
17
- * [Stimulus.js](https://stimulus.hotwired.dev/)
18
- * [Turbo](https://turbo.hotwired.dev/)
19
- * [Swiper.js](https://swiper.com/)
20
- * [PhotoSwipe](https://photoswipe.com/)
21
- * [noUISlider](https://refreshless.com/nouislider/)
22
- * [card-validator](https://github.com/braintree/card-validator) and [credit-card-type](https://github.com/braintree/credit-card-type)
23
-
24
- You can find them in the [app/assets/javascripts/vendor](https://github.com/spree/spree/blob/main/storefront/vendor/javascript) directory.
25
-
26
- ### Managing JavaScript dependencies
27
-
28
- You're probably wondering why these libraries are in the `vendor` directory, and not in `node_modules`.
29
-
30
- That's because we're not using Node.js at all. So no Yarn or npm. We're using a different approach to manage dependencies.
31
-
32
- We're using a tool called [Importmaps](https://github.com/rails/importmap-rails) to manage dependencies which is the Ruby on Rails default.
33
-
34
- > **INFO:** If you want to use a different JavaScript package manager you can do so by using [jsbundling-rails](https://github.com/rails/jsbundling-rails) gem.
35
-
36
- #### Install dependencies
37
-
38
- To install dependencies you need to run the following command:
39
-
40
- ```bash
41
- bin/importmap pin react
42
- ```
43
-
44
- This will install the dependencies, download the files to your `vendor/javascript` directory and add them to your `config/importmap.rb` file, eg.
45
-
46
- ```ruby
47
- pin "react" # @19.1.0
48
- ```
49
-
50
- Now you can just import the library in your application entry point, eg. `application.js`:
51
-
52
- ```js
53
- import "react";
54
- ```
55
-
56
- ### Application entry point
57
-
58
- Mentioned above, the application entry point is the `application.js` file. It's located in the `app/javascript` directory.
59
-
60
- If you want to add custom JavaScript to your Spree storefront, you can do so by adding a new file to the `app/javascript` directory.
61
-
62
- ### Stimulus Controllers
63
-
64
- Stimulus controllers are a way to add interactivity to your Spree storefront. Storefront controllers can be found in the Spree repository in the [storefront/app/javascript/spree/storefront/controllers](https://github.com/spree/spree/tree/main/storefront/app/javascript/spree/storefront/controllers) directory.
65
-
66
- You can find more information about Stimulus controllers in the [Stimulus.js documentation](https://stimulus.hotwired.dev/handbook/controllers).
67
-
68
- To add a new controller you need to create a new file in the `app/javascript/controllers` directory. It will be automatically picked up by the application.
69
-
70
- ```js
71
- // app/javascript/controllers/hello_controller.js
72
- import { Controller } from '@hotwired/stimulus'
73
-
74
- export default class extends Controller {
75
- connect() {
76
- console.log("Hello Spree Commerce Stimulus!", this.element);
77
- }
78
- }
79
- ```
80
-
81
- To use the controller in your HTML you need to add the `data-controller` attribute to your element, eg.
82
-
83
- ```html
84
- <div data-controller="hello">
85
- Hello Spree Commerce Stimulus!
86
- </div>
87
- ```
88
-
89
- ## JavaScript snippets
90
-
91
- If you need to add a small piece of JavaScript code (eg. tracking, marketing, analytics, customer service etc.) you can do this by:
92
-
93
- 1. Declaring a new head partial in the `config/initializers/spree.rb` file, eg.
94
-
95
- **Spree 5.2+:**
96
-
97
- ```ruby config/initializers/spree.rb
98
- Rails.application.config.after_initialize do
99
- Spree.storefront.partials.head << 'spree/shared/my_tracking_code'
100
- end
101
- ```
102
-
103
- **Spree 5.1 and below:**
104
-
105
- ```ruby config/initializers/spree.rb
106
- Rails.application.config.spree_storefront.head_partials << 'spree/shared/my_tracking_code'
107
- ```
108
-
109
-
110
- 2. Creating a new file in the `app/views/spree/shared/my_tracking_code.html.erb`, where you can add your tracking code, eg.
111
-
112
- ```erb app/views/spree/shared/my_tracking_code.html.erb
113
- <script>
114
- console.log("I'm a spy!");
115
- </script>
116
- ```
117
-
118
- > **INFO:** Check out the [Integrations](/integrations) for existing integrations you can plug into your storefront.
119
-
120
- ## Extending Existing Stimulus Controllers
121
-
122
- You can extend or override existing Storefront Stimulus controllers:
123
-
124
- ```js
125
- // app/javascript/controllers/cart_controller.js
126
-
127
- export default class extends CartController {
128
- connect() {
129
- super.connect()
130
- console.log('Extended cart controller connected!')
131
- }
132
-
133
- // Override existing method
134
- addItem(event) {
135
- // Custom logic before adding
136
- console.log('Adding item...')
137
- super.addItem(event)
138
- // Custom logic after adding
139
- }
140
- }
141
- ```
142
-
143
- ## Turbo Events
144
-
145
- Spree Storefront uses [Turbo](https://turbo.hotwired.dev/) for navigation. You can hook into Turbo events:
146
-
147
- ```js
148
- // app/javascript/application.js
149
- document.addEventListener('turbo:load', () => {
150
- console.log('Page loaded via Turbo')
151
- })
152
-
153
- document.addEventListener('turbo:before-visit', (event) => {
154
- console.log('About to visit:', event.detail.url)
155
- })
156
-
157
- document.addEventListener('turbo:frame-load', (event) => {
158
- console.log('Turbo frame loaded:', event.target.id)
159
- })
160
- ```
161
-
162
- ## Related Documentation
163
-
164
- - [Custom CSS](/developer/storefront/custom-css) - Styling your storefront
165
- - [Sections](/developer/storefront/sections) - Creating custom sections
166
- - [Blocks](/developer/storefront/blocks) - Creating custom blocks