Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget editor: adds tabs #4514

Merged
merged 10 commits into from Apr 30, 2024
Merged

Widget editor: adds tabs #4514

merged 10 commits into from Apr 30, 2024

Conversation

falkodev
Copy link
Contributor

@falkodev falkodev commented Apr 23, 2024

https://linear.app/apostrophecms/issue/PRO-5134/widget-modals-that-support-schema-tabsgroups

Add a widget with no contextual editing and check widgets can be inserted/updated and their fields are scattered throughout tabs respecting the configuration.

image
image
image

Example of a widget I added on my homepage (note the group object in config):

// in modules/image-widget/index.js
module.exports = {
  extend: '@apostrophecms/widget-type',
  options: {
    icon: 'image-icon',
    label: 'Rich Image',
    description: 'Display an image on your page'
  },
  fields: {
    add: {
      _image: {
        type: 'relationship',
        withType: '@apostrophecms/image',
        label: 'Image',
        required: true,
        max: 1
      },
      alt: {
        type: 'string',
        label: 'Alt Text',
        help: 'Descriptive text for screen readers and search engines'
      },
      credit: {
        type: 'string',
        label: 'Credit',
        help: 'Who should be credited for this image?'
      },
      credit2: {
        type: 'string',
        label: 'Credit 2',
        help: 'Who should be credited for this image?'
      },
      credit3: {
        type: 'string',
        label: 'Credit 3',
        help: 'Who should be credited for this image?'
      },
      credit4: {
        type: 'string',
        label: 'Credit 4',
        help: 'Who should be credited for this image?'
      },
      credit5: {
        type: 'string',
        label: 'Credit 5',
        help: 'Who should be credited for this image?'
      },
      credit6: {
        type: 'string',
        label: 'Credit 6',
        help: 'Who should be credited for this image?'
      }
    },
    group: {
      basics: {
        label: 'Basics',
        fields: [ '_image' ]
      },
      content: {
        label: 'Content',
        fields: [ 'alt' ]
      },
      settings: {
        label: 'Settings',
        fields: [ 'credit' ]
      },
      settings2: {
        label: 'Settings 2 with a long label',
        fields: [ 'credit2' ]
      },
      settings3: {
        label: 'Settings 3',
        fields: [ 'credit3' ]
      },
      settings4: {
        label: 'Settings 4',
        fields: [ 'credit4' ]
      },
      settings5: {
        label: 'Settings 5',
        fields: [ 'credit5', 'credit6' ]
      }
    }
  }
};
<!-- in modules/image-widget/views/widget.html -->
<section data-aos="{{ data.widget.animationEffects }}" class="container widget-my-spacing">
  {% if data.widget.aposPlaceholder and data.manager.options.placeholderUrl %}
    <img
      src="{{ data.manager.options.placeholderUrl }}"
      alt="{{ __t('apostrophe:imagePlaceholder') }}"
      class="image-widget-placeholder"
    />
  {% else %}
    {% set className = data.options.className or data.manager.options.className %}
    {% set dimensionAttrs = data.options.dimensionAttrs or data.manager.options.dimensionAttrs %}
    {% set loadingType = data.options.loadingType or data.manager.options.loadingType %}
    {% set size = data.options.size or data.manager.options.size or 'full' %}

    {% set attachment = apos.image.first(data.widget._image) %}

    {% if attachment %}
      <img {% if className %} class="{{ className }}"{% endif %}
        {% if loadingType %} loading="{{ loadingType }}"{% endif %}
        srcset="{{ apos.image.srcset(attachment) }}"
        src="{{ apos.attachment.url(attachment, { size: size }) }}"
        alt="{{ attachment._alt or '' }}"
        {% if dimensionAttrs %}
          {% if attachment.width %} width="{{ apos.attachment.getWidth(attachment) }}" {% endif %}
          {% if attachment.height %} height="{{ apos.attachment.getHeight(attachment) }}" {% endif %}
        {% endif %}
        {% if data.contextOptions and data.contextOptions.sizes %}
          sizes="{{ data.contextOptions.sizes }}"
        {% endif %}
        {% if apos.attachment.hasFocalPoint(attachment) %}
          style="object-position: {{ apos.attachment.focalPointToObjectPosition(attachment) }}"
        {%- endif -%}
      />
    {% endif %}
  {% endif %}
</section>

then in homepage

fields: {
    add: {
      main: {
        type: 'area',
        options: {
          widgets: {
             image: {}
          }
        }
      }
    },

Copy link

linear bot commented Apr 23, 2024

@falkodev falkodev marked this pull request as ready for review April 25, 2024 13:35
@falkodev falkodev marked this pull request as draft April 25, 2024 13:36
@falkodev falkodev marked this pull request as ready for review April 26, 2024 08:06
@falkodev falkodev requested a review from boutell April 26, 2024 08:06
Copy link
Member

@boutell boutell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally great, need to fix that prop mutation though.

@falkodev falkodev requested a review from boutell April 26, 2024 15:24
boutell
boutell previously approved these changes Apr 30, 2024
Copy link
Member

@boutell boutell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with my shallow clone fix (assigning to a variable doesn't copy the object).

@boutell boutell requested a review from BoDonkey April 30, 2024 19:19
@BoDonkey BoDonkey merged commit a6bb2b2 into main Apr 30, 2024
8 checks passed
@BoDonkey BoDonkey deleted the pro-5134-widget-editor-tabs branch April 30, 2024 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants