siteorigin / siteorigin-panels

SiteOrigin Page Builder is a powerful content creation interface, instantly recognizable, astonishingly different. SiteOrigin Page Builder makes it easy to create responsive column-based content using the widgets you know and love. Your content will accurately adapt to all mobile devices, ensuring your site is mobile-ready.
https://siteorigin.com/page-builder/
GNU General Public License v3.0
610 stars 182 forks source link

Custom Background Image Display #429

Open alenb opened 7 years ago

alenb commented 7 years ago

Hey guys,

At the moment the background image display is a dropdown which has a few options, however, it lacks a custom option. In a lot of circumstances you'd want/need to tweak the position of a background on an element. It would be highly beneficial to have a custom option or replacing the dropdown with an input box altogether. Just an idea.

I assume the idea was to use the CSS Styles box when a custom display was needed? And the dropdown is there as a 'quick select' type of thing?

AlexGStapleton commented 7 years ago

I assume the idea was to use the CSS Styles box when a custom display was needed? And the dropdown is there as a 'quick select' type of thing?

Basically, yes.

I'm all for this idea but I'm not too sure it could be handled design wise. Thoughts?

alenb commented 7 years ago

An input box would help non-code savvy folk make changes to the background position without having to do it via CSS Styles. It would also keep things grouped together when it comes to background stylings under the design tab. Although, I don't know if this is a strong enough reason to make a change like that. In all honesty, they ought to learn some CSS anyways hehe

What I might do is, I'll fork it and try it out. If it looks good, I'll submit it and you can take a look.

andrejarh commented 5 years ago

Design wise, I think there are other things to consider, if a decision is made for such control to be built. Background-position is just one of background related CSS properties. Others are at least background size (cover, contain), background-repeat...

@alenb What you can do currently about it is to add your own options inside the select box with php:

/* PHP */
/* Create the option */
function add_custom_row_bg_styles( $form_options, $fields ) {
    $form_options['background_display']['options']['CustomHtmlClass'] = 'your option';
}
add_filter('siteorigin_panels_row_style_fields', 'add_custom_row_bg_styles', 10, 2);

/* Add a special HTML class */
function custom_row_style_attributes( $attributes, $args ) {
    if (isset($args['background_display']) && $args['background_display'] == 'CustomHtmlClass') {
        array_push($attributes['class'], 'CustomHtmlClass');
    }                   
    return $attributes;   
}
add_filter('siteorigin_panels_row_style_attributes', 'custom_row_style_attributes', 1, 2);

You will be then able to style it then with CSS (basic example):

.CustomHtmlClass {
background-postition: left top!important;
}