BotFramework-WebChat icon indicating copy to clipboard operation
BotFramework-WebChat copied to clipboard

Can we style Hero card buttons as rounded corners?

Open dnyati opened this issue 7 years ago • 4 comments

I have PromptOptions with ListStyle as HeroCard,. By detault it comes as rectangle. Can we style it look like rounded corner & change color & thickness' of borders? Bot developed in SDK 4 C#. Need this for web chat channel. Thanks!

Screenshots

Version

Describe the bug

To Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

Additional context

[Bug]

dnyati avatar Nov 20 '19 10:11 dnyati

Assigning to @CoHealer in lieu of @stevkan, please feel free to update if there are status changes.

corinagum avatar Nov 20 '19 18:11 corinagum

@dnyati, you can use the following hack to alter the styling of a card. A few things to note:

  • You need to match to a value that is passed in the card, not in the activity. This allows you to identify the specific card(s) in the html document to be styled. I'm matching on the button text value, for simplicity.
  • Hero cards, with respect to the document, are rendered as adaptive cards which is why I am filtering by the ac-adaptiveCard class.
  • I recast the adaptiveCards [HtmlCollection] object as a true array (cards) for iterating.
  • I add the trigger class for mapping the CSS to the card(s).
  • The border of the card is contained within the chat bubble. As seen in the image below, the bubble background extends beyond the card border. You can adjust the bubble styling via the styleOptions web chat control, example here.

First, create the store and filter on incoming activities, messages, and on whichever element value you choose. Then, assign the class to the card.

const store = window.WebChat.createStore( {}, ( { dispatch } ) => next => async action => {
  if ( action.type === 'DIRECT_LINE/INCOMING_ACTIVITY' ) {
    if ( activity.type === 'message') {
      let adaptiveCards = document.body.getElementsByClassName('ac-adaptiveCard');
      let cards = Object.values(adaptiveCards);
      for(let i = 0; i <= cards.length - 1; i++) {
        if( cards[i].children[2] && cards[i].children[2].innerText && cards[ i ].children[ 2 ].innerText === 'Service details') {
          cards[i].className += ' trigger';
        }
      }
    }
  }
}

Assign the CSS styling by matching on the assigned class, .trigger in this case.

.ac-container.ac-adaptiveCard.trigger {
  border-style: solid;
  border-color: red;
  border-radius: 5px;
  border-width: 2px;
}

Pass the store as a parameter.

window.ReactDOM.render(
  <ReactWebChat
    directLine={ directLine }
    store={store}
  />,
  document.getElementById( 'webchat' )
);

image

Hope of help!

stevkan avatar Nov 21 '19 20:11 stevkan

I'm closing the issue as resolved. Please feel free to reopen should you encounter additional challenges related to this.

stevkan avatar Nov 21 '19 20:11 stevkan

Hi ,

Hero Card Buttons Thanks for the response this is very helpful & sorry for late reply as busy with other projects. I tried above example but when I make change it continuously goes in connecting mode & bot does not start. If I remove store it works well. I have attached my file for your reference. BotFrame.txt

dnyati avatar Jun 07 '20 16:06 dnyati