aptos-labs / aptos-wallet-adapter

A monorepo modular wallet adapter for Aptos applications
https://aptos-labs.github.io/aptos-wallet-adapter/
Apache License 2.0
88 stars 97 forks source link

Improve compositionability a bit in react lib's createHeadlessComponent helper #435

Open psd-coder opened 5 days ago

psd-coder commented 5 days ago

This PR improves createHeadlessComponent util behavior: if asChild is set and children is valid react element with empty children props (to not override custom children there) then will be used children from props.

Before change

Right now if you use asChild for passing props to children you won't get a default children value from the defaults.

For example this won't work and will give empty <p class="text-primary"></p>

<AptosPrivacyPolicy.Disclaimer asChild>
  <p className="text-primary" />
</AptosPrivacyPolicy.Disclaimer>

After the change

<AptosPrivacyPolicy.Disclaimer asChild>
  <p className="text-primary" />
</AptosPrivacyPolicy.Disclaimer>

will give you <p class="text-primary">By continuing, you agree to Aptos Labs'</p>

and if you specify children in internal element, then

<AptosPrivacyPolicy.Disclaimer asChild>
  <p className="text-primary">By continuing, you agree with the policy</p>
</AptosPrivacyPolicy.Disclaimer>

will give you <p className="text-primary">By continuing, you agree with the policy</p>