Skip to content

Commit

Permalink
Merge pull request #71 from N1ck/extra-adjustments-button-width
Browse files Browse the repository at this point in the history
Update toolbar width logic
  • Loading branch information
N1ck authored Jan 8, 2024
2 parents 8c619b4 + 38e48c9 commit d1b764e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/components/giphy-toolbar-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React from 'dom-chef'

export default (
<details class=" details-reset details-overlay toolbar-item select-menu select-menu-modal-right ghg-trigger">
<details class="details-reset details-overlay toolbar-item select-menu select-menu-modal-right ghg-trigger">
<summary
class="menu-target Button Button--iconOnly Button--invisible Button--medium"
aria-label="Insert a GIF"
Expand Down
52 changes: 29 additions & 23 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,6 @@ function addToolbarButton() {
'#review-changes-modal .SelectMenu-list'
)

// Add a specific class if the form is in the review changes modal, or if it is in the review changes list
// Otherwise the GIF selection popover will not be visible.
if (reviewChangesModal !== null) {
reviewChangesModal.classList.add('ghg-in-review-changes-modal')

// The Review changes modal sets an inline width of min(640px, 100vw - 2rem);
// our button takes up another 32px so we need to adjust the inline style to account for that, otherwise it's hidden.
const currentWidth = reviewChangesModal.style.width
if (currentWidth.includes('px')) {
// Extracts the value from the string (e.g., 640 from "min(640px, 100vw - 2rem)")
const widthValue = Number.parseInt(currentWidth.match(/\d+/)[0], 10)
const modifiedWidth = currentWidth.replace(
widthValue + 'px',
`${widthValue + 32}px`
)
reviewChangesModal.style.width = modifiedWidth
}
}

if (reviewChangesList !== null) {
reviewChangesList.classList.add('ghg-in-review-changes-list')
}

// Observe the toolbars without the giphy field, add
// the toolbar item to any new toolbars.
observeEl(toolbar, () => {
Expand Down Expand Up @@ -152,6 +129,35 @@ function addToolbarButton() {
resetGiphyModals()
}
})

// Add a specific class if the form is in the review changes modal, or if it is in the review changes list
// Otherwise the GIF selection popover will not be visible.
if (reviewChangesModal !== null) {
reviewChangesModal.classList.add('ghg-in-review-changes-modal')

// The Review changes modal sets an inline width of min(640px, 100vw - 2rem);
// our button takes up another 32px so we need to adjust the inline style to account for that, otherwise it's hidden.
const currentWidth = reviewChangesModal.style.width

const trigger = select('.ghg-trigger', form)
// Calculate the width of the GIF button, so that we can adjust the toolbar min size to accommodate for it.
// Also add 8 px buffer
const triggerWidth = (trigger?.offsetWidth ?? 32) + 8

if (currentWidth.includes('px')) {
// Extracts the value from the string (e.g., 640 from "min(640px, 100vw - 2rem)")
const widthValue = Number.parseInt(currentWidth.match(/\d+/)[0], 10)
const modifiedWidth = currentWidth.replace(
widthValue + 'px',
`${widthValue + triggerWidth}px`
)
reviewChangesModal.style.width = modifiedWidth
}
}

if (reviewChangesList !== null) {
reviewChangesList.classList.add('ghg-in-review-changes-list')
}
}
}

Expand Down

0 comments on commit d1b764e

Please sign in to comment.