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

How to style custom buttons in the menu bar? #169

Closed
jtuchel opened this issue Oct 19, 2022 · 7 comments
Closed

How to style custom buttons in the menu bar? #169

jtuchel opened this issue Oct 19, 2022 · 7 comments
Labels
question Further information is requested

Comments

@jtuchel
Copy link

jtuchel commented Oct 19, 2022

I tried to setup a "download" button that should appear in the menu bar

  const downloadButton: MenuButtonItem = {
    onClick: saveDocumentToDisk,
    // icon: {}, // download icon
    text: "Save to disk",
    title: "Save this document to disk",
    className: "jse-button",
  };

Unfortunately it looks like

image

I want it to look like the original one ( taken from here https://jsoneditoronline.org/ )

image

Would you mind telling me what's wrong/missing? Is there a public repository for jsoneditoronline I can have a look at?

It would be fine for me if there is no text, just the icon as a button!

@josdejong
Copy link
Owner

There is an example of a custom menu button with just an icon and no text here: https://github.com/josdejong/svelte-jsoneditor/blob/main/src/routes/examples/custom_menu_buttons/%2Bpage.svelte

By default, the button will be styled like the other buttons in the menu of the editor. You can give the button a className though and apply your own styling with CSS (like demonstrated in the example above too).

It is not possible to create dropdown menu though like in the screenshot you post from https://jsoneditoronline.org/. The repo of jsoneditoronline is not public though, but it has a custom dropdown menu component for this second menu bar.

@josdejong josdejong added the question Further information is requested label Oct 20, 2022
@jtuchel
Copy link
Author

jtuchel commented Oct 20, 2022

@josdejong thanks for your reply. I installed FontAwesome for my Vue app and I'm trying to reproduce your linked Svelte example. I started with this

<script setup lang="ts">
import type { FontAwesomeIcon } from "vanilla-jsoneditor";
import { faCopy } from '@fortawesome/free-regular-svg-icons';

const myIcon: FontAwesomeIcon = {
  prefix: faCopy.prefix,
  iconName: faCopy.iconName,
  icon: faCopy.icon // this is not possible
};
</script>

I can't assign faCopy.icon to FontAwesomeIcon.icon because of

TS2322: Type '[number, number, string[], string, IconPathData]' is not assignable to type '[number, number, (string | number)[], string, string]'.

faCopy is not of type FontAwesomeIcon, its type is IconDefinition. Did I miss something?

@josdejong
Copy link
Owner

Good point. I had some troubles with the type definitions of fontawesome and created my own definition FontAwesomeIcon instead. This type doesn't match exactly with the type from fontawesome itself. I'll get rid of the custom interface and use IconDefinition. There is a type IconName used in IconDefinition which prevents from defining a new custom icon, but with a fake cast "... as IconName" we can make TypeScript happy 😢 .

@josdejong josdejong reopened this Oct 21, 2022
@josdejong
Copy link
Owner

I've fixed the issue via 9d693f9 (not yet published)

@jtuchel
Copy link
Author

jtuchel commented Oct 24, 2022

I've fixed the issue via 9d693f9 (not yet published)

Thanks for your efforts :) Do you have any plans when this will be released?

@josdejong
Copy link
Owner

👍 I've published the fix now in v0.8.0.

@jtuchel
Copy link
Author

jtuchel commented Oct 24, 2022

Working perfectly fine :)

@jtuchel jtuchel closed this as completed Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants