.gitkeep
3 years ago
block-helpers.php
1 year ago
block-style-helpers.php
6 months ago
collection-helpers.php
2 days ago
cookie-helpers.php
1 year ago
kses-helpers.php
4 months ago
product-helpers.php
3 months ago
product-review-helpers.php
4 months ago
route-helper.php
2 years ago
state-helpers.php
2 years ago
template-helpers.php
4 months ago
block-style-helpers.php
51 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Get the current block styles. |
| 4 | * |
| 5 | * @param bool $combine Whether to combine the styles or not. |
| 6 | * @param object $block The block object. |
| 7 | * @return array |
| 8 | */ |
| 9 | function sc_get_block_styles( $combine = true, $block = null ) { |
| 10 | return \SureCart::block()->styles()->get( $combine, $block ); |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * Get cart block style. |
| 15 | * |
| 16 | * @param array $attributes |
| 17 | * |
| 18 | * @return string |
| 19 | */ |
| 20 | function sc_get_cart_block_style( $attributes ) { |
| 21 | $style = ''; |
| 22 | |
| 23 | // Border style. |
| 24 | $style .= isset( $attributes['border'] ) && $attributes['border'] !== false ? 'border-bottom: var(--sc-drawer-border);' : ''; |
| 25 | |
| 26 | // Padding style. |
| 27 | $style .= ! empty( $attributes['padding']['top'] ) ? 'padding-top: ' . $attributes['padding']['top'] . ';' : ''; |
| 28 | $style .= ! empty( $attributes['padding']['bottom'] ) ? 'padding-bottom: ' . $attributes['padding']['bottom'] . ';' : ''; |
| 29 | $style .= ! empty( $attributes['padding']['left'] ) ? 'padding-left: ' . $attributes['padding']['left'] . ';' : ''; |
| 30 | $style .= ! empty( $attributes['padding']['right'] ) ? 'padding-right: ' . $attributes['padding']['right'] . ';' : ''; |
| 31 | |
| 32 | // Background color style. |
| 33 | $style .= ! empty( $attributes['backgroundColor'] ) ? 'background-color: ' . $attributes['backgroundColor'] . ';' : ''; |
| 34 | |
| 35 | // Text color style. |
| 36 | $text_color = $attributes['textColor'] ?? 'var(--sc-line-item-title-color, var(--sc-input-label-color))'; |
| 37 | $style .= 'color: ' . $text_color . ';'; |
| 38 | |
| 39 | return $style; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Convert an array to a string of inline styles. |
| 44 | * |
| 45 | * @param array $styles The styles to convert. |
| 46 | * @return string The string of inline styles. |
| 47 | */ |
| 48 | function sc_get_inline_styles( $styles ) { |
| 49 | return implode( ';', array_map( fn( $key, $value ) => "$key:$value", array_keys( $styles ), array_filter( $styles ?? [] ) ) ); |
| 50 | } |
| 51 |