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

[Feature] Custom Action Buttons below poster #996

Closed
1 task done
revantemp3 opened this issue Aug 15, 2024 · 2 comments
Closed
1 task done

[Feature] Custom Action Buttons below poster #996

revantemp3 opened this issue Aug 15, 2024 · 2 comments

Comments

@revantemp3
Copy link

revantemp3 commented Aug 15, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe.

hi, filepond is excellent, it is so beautiful

i have created a plugin for creating extra buttons based on the metadata actions. It works but i need help with styling

Current problems is

  1. filepond--action-buttons is above and overlap filepond--file-poster-wrapper. i need the buttons to be below the poster-wrapper
  2. when using createChildView, it becomes a round button when i need square. it also becomes elongated horizontally because of the text
  3. the text is not visible even though the element for the text is existent and not hidden

i feel that fileActionButton is not suitable for my purpose. is there a better built in? otherwise, can you point me in the direction to make one?
also i feel that some of the issues have to do with the order of rendering. the buttons should wait until the preview poster is created.

cheers,
RT

const plugin = (fpAPI) => {
  const { addFilter, utils, views } = fpAPI;
  const { Type, createRoute } = utils;
  const { fileActionButton } = views;

  const createActionButtonsView = (_) =>
    _.utils.createView({
      name: 'action-buttons',
      ignoreRect: true,
      create: ({ root, props }) => {
        const { actions } = props;

        actions.forEach((action) => {
          const button = root.createChildView(fileActionButton, {
            label: action.text,
            icon: action.icon || '',
            opacity: 1
          });
          button.element.classList.add('filepond--action-buttons');
          button.on('click', () => action.func(action.parameters));
          root.ref[`button${action.text}`] = root.appendChildView(button);
        });
      },
      write: createRoute({
        DID_UPDATE_ITEM_METADATA: ({ root, props }) => {
          // Update logic if needed
        }
      })
    });

  addFilter('CREATE_VIEW', (viewAPI) => {
    const { is, view, query } = viewAPI;

    if (!is('file') || !query('GET_ALLOW_FILE_ACTIONS')) return;

    const didLoadItem = ({ root, props }) => {
      const { id } = props;
      const item = query('GET_ITEM', id);

      if (item && item.getMetadata('actions')) {
        const actions = item.getMetadata('actions');
        root.ref.actionButtons = view.appendChildView(
          view.createChildView(createActionButtonsView(fpAPI), { actions })
        );
      }
    };

    view.registerWriter(
      createRoute({
        DID_LOAD_ITEM: didLoadItem,
        DID_UPDATE_ITEM_METADATA: ({ root, props, action }) => {
          if (!/actions/.test(action.change.key)) return;
          if (root.ref.actionButtons) {
            view.removeChildView(root.ref.actionButtons);
          }
          didLoadItem({ root, props });
        }
      })
    );
  });

  return {
    options: {
      allowFileActions: [true, Type.BOOLEAN],
    },
  };
};

const isBrowser =
  typeof window !== 'undefined' && typeof window.document !== 'undefined';
if (isBrowser) {
  document.dispatchEvent(
    new CustomEvent('FilePond:pluginloaded', { detail: plugin })
  );
}

export default plugin;

Describe the solution you'd like

when the script runs, based on the buttons in actions
poster
button1
button2
button3

Describe alternatives you've considered

I tried doing a DOM manipulation by adding button directly. it got squeezed into top right hand corner and was made invisible

@revantemp3
Copy link
Author

turns out i just need to use a lot of global css to override the default settings

.filepond--action-buttons {
display: flex;
justify-content: center;
margin-top: 10px;
}
.filepond--file-action-button.filepond--action-buttons-sp {
background-color: white;
color: black;
border: 1px solid black;
border-radius: 1rem;
cursor: pointer;
transition: all 0.3s ease;
position: relative;
}

/* .filepond--file-action-button.filepond--action-buttons-sp:hover {
background-color: #f0f0f0;
} */

.filepond--file-action-button.filepond--action-buttons-sp span {
color: black;
z-index: 99;
width: none !important;
height: none !important;
position: relative !important;
clip: auto !important;
clip-path: none !important;
-webkit-clip-path: none !important;
}
/* Global styles */
.filepond--item {
width: 23% !important;
}

.filepond--file-wrapper {
position: relative;
height: 100%;
}

.filepond--file {
height: 100%;
position: static;
display: flex;
flex-direction: column;
}

.filepond--file-poster {
width: 100% !important;
height: 100% !important;
object-fit: contain;
object-position: center;
}

.filepond--action-buttons {
position: static !important;
bottom: 0;
left: 0;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
margin-top: 2px !important;
}

.filepond--action-buttons .filepond--file-action-button {
margin-bottom: 5px;
width: 80%; /* Adjust as needed */
}

.filepond--file-poster-wrapper {
width: 100% !important;
height: 100% !important;
position: static !important;
display: flex;
align-items: center;
justify-content: center;
}

.filepond--image-preview-wrapper {
width: 100% !important;
height: 100% !important;
}

.filepond--image-preview {
width: 100% !important;
height: 100% !important;
object-fit: contain;
object-position: center;
}

@rikschennink
Copy link
Collaborator

Yeah, the action button is a styled button, you'd have to duplicate the view and create a basic variant to make a plain version. But indeed overriding styles works as well.

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

No branches or pull requests

2 participants