Git Product home page Git Product logo

Comments (2)

Insality avatar Insality commented on August 15, 2024 1

Right now extending components is not designed, but can be done with a little trick.

I will think more about this ability, should be it in Druid or not. Druid prefer composition and customizing components via styles should be enough. If you want replace all buttons, current way is copy button component, rework it and register at druid via druid.register(). Register can override basic components too.

Trick: for now, you can create subclass from druid component in next-way:

local class = require("druid.system.middleclass")
local button = require("druid.base.button")

local M = class("button_custom", button)

--- Class constructor
function M.initialize(self)
	--- Call parent constructor
	button.initialize(self)
end

function M.is_enabled(self)
	print("Overridden function")
	return not self.disabled
end

return M

Thanks for feedback! Issue will be closed after solution for this.

from druid.

GreenArrow18 avatar GreenArrow18 commented on August 15, 2024

I was trying to do it using styles only, but I can't quite figure out how to add some properties to it (for example, save the original node's color so I can manipulate it later).

I wanted to avoid copy/paste of the original button codes, because it pretty much contains the basic functionality already, so for easier code maintenance, I just like to extend it.

Your solution above actually works perfectly for my use case! I set the properties in this new extended component, then use those properties in my new style, without having to mess around further with the original button codes.

Thanks again!

from druid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.