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

Buttons 8: Connect frontend with view button classes #6546

Merged
merged 1 commit into from
Jul 25, 2024

Conversation

distantnative
Copy link
Member

@distantnative distantnative commented Jul 20, 2024

Description

Summary of changes

  • Connect new backend classes with frontend
  • Integrate in Panel\Model classes
  • Exclude area buttons configs from code coverage

Changelog

Features

  • Define custom view buttons in your blueprints or config
  • Custom Panel are buttons extension

Docs

As with the previous PR, view buttons can be defined by names in a model blueprint or for all views in the config.

Define custom button in config

However, one can now even define whole buttons by setting an array instead of a name string. The array consist of a component key (optional, if omitted k-view-button will be used) and a props array.

Via config:

'panel' => [
	'viewButtons' => [
		'site' => [
			'preview',
			'a' => [
				'props' => [
					'icon'   => 'heart',
					'text'   => 'Kosmos',
					'theme'  => 'purple-icon',
					'target' => '_blank',
					'link'   => 'https://getkirby.com'
				]
			],
			'b-dropdown' => [
				'props' => [
					'icon'     => 'info',
					'text'     => 'Info',
					'dropdown' => 'my/dropdown/route'
				]
			],
			'c-component' => [
				'component' => 'my-custom-component',
				'props' => [
					'foo' => 'bar'
				]
			]
		]
	]
]

Shorthand for only props

If you don't pass a component-props definition, you can also just pass the props on their own, being then applied to k-view-button:

'panel' => [
	'viewButtons' => [
		'site' => [
			'a' => [
				'icon'   => 'heart',
				'text'   => 'Kosmos',
				'theme'  => 'purple-icon',
				'target' => '_blank',
				'link'   => 'https://getkirby.com'
			]
		]
	]
]

Define custom button in a blueprint

This also works in blueprints:

buttons:
  - preview
  - settings
  foo:
      text: Foo

Reusable buttons: Panel area buttons extension

If you do not want to define just one button via the config, but reuse it (or even ship it as part of your plugin), you have to add them to the Panel area extension:

Kirby::plugin('custom/buttons', [
	'areas' => [
		'todos' => function () {
			return [
				'buttons' => [
					'todos.add' => function () {
						return [
							'props' => [
								'icon'   => 'add',
								'dialog' => 'todos/create'
							]
						];
					}
				]
			];
		}
	]
]);

You have the same options for your return value: full component-props array or just props on top-level. In addition, you can also return directly a Kirby\Panel\Ui\Button\ViewButton object.

See Kirby\Panel\Ui\Button\ViewButton properties for available props options (also for array notation).

Ready?

  • In-code documentation (wherever needed)
  • Unit tests for fixed bug/feature
  • Tests and CI checks all pass

For review team

@distantnative distantnative added the type: feature 🎉 Adds a feature (requests → feedback.getkirby.com) label Jul 20, 2024
@distantnative distantnative added this to the 5.0.0-alpha.2 milestone Jul 20, 2024
@distantnative distantnative self-assigned this Jul 20, 2024
@distantnative distantnative force-pushed the v5/buttons/8-connect-all branch 2 times, most recently from 6b169fb to 5e4b161 Compare July 22, 2024 11:14
@bastianallgeier bastianallgeier marked this pull request as ready for review July 24, 2024 09:38
@distantnative
Copy link
Member Author

The missing code coverage is about the existing view config. I would suggest to ignore it here and rather tackle refactoring and testing the views separately.

Copy link
Member

@bastianallgeier bastianallgeier left a comment

Choose a reason for hiding this comment

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

I love how the different pieces are coming together. This is really pushing us in a great new direction with backend and frontend integrations.

@bastianallgeier bastianallgeier merged commit 868fca6 into v5/develop Jul 25, 2024
14 of 15 checks passed
@bastianallgeier bastianallgeier deleted the v5/buttons/8-connect-all branch July 25, 2024 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature 🎉 Adds a feature (requests → feedback.getkirby.com)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants